# overwriteCommand

The browser method `overwriteCommand` helps you to overwrite the browser's and element's native commands like `pause` and `click`.

info

You can view more information on this in the [custom command](/docs/customcommands.md#overwriting-native-commands) section.

## Usage[​](#usage "Direct link to Usage")

```
browser.overwriteCommand(name, callback, { attachToElement })
```

## Parameters[​](#parameters "Direct link to Parameters")

| Name                                      | Type       | Details                                                 |
| ----------------------------------------- | ---------- | ------------------------------------------------------- |
| `name`                                    | `string`   | name of the original command                            |
| `callback`                                | `Function` | pass original function                                  |
| `options`<br />*optional*                 | `Object`   | options object                                          |
| `options.attachToElement`<br />*optional* | `Boolean`  | extend the Element object instead of the Browser object |

## Example[​](#example "Direct link to Example")

execute.js

```
// print milliseconds before pause and return its value.

await browser.overwriteCommand('pause', function (origPauseFunction, ms) {

    console.log(`Sleeping for ${ms}`)

    origPauseFunction(ms)

    return ms

})



// overwrite an element command

await browser.overwriteCommand('click', function (origClickFunction) {

    console.log('clicking')

    return origClickFunction()

}, { attachToElement: true })



// usage

it('should use my overwrite command', async () => {

    await browser.url('https://webdriver.io')

    await browser.pause(1000) // outputs "Sleeping for 1000"

})
```
