# throttleNetwork

Throttle the network capabilities of the browser. This can help to emulate certain scenarios where a user loses their internet connection and your app needs to address that.

There are many presets available with default configurations for ease of use. They are `offline`, `GPRS`, `Regular2G`, `Good2G`, `Regular3G`, `Good3G`, `Regular4G`, `DSL`, `WiFi`, `online`.

You can see the values for these presets [in the source code](https://github.com/webdriverio/webdriverio/blob/6824e4eb118a8d20685f12f4bc42f13fd56f8a25/packages/webdriverio/src/commands/browser/throttleNetwork.js#L29).

info

Service workers initiate requests through their own network stack. This command applies the throttling conditions to every service worker that is registered at the time of the call. If your app registers a service worker afterwards, call `throttleNetwork` again to cover it.

Note that using the `throttleNetwork` command requires support for Chrome DevTools protocol and e.g. can not be used when running automated tests in the cloud. Chrome DevTools protocol is not installed by default, use `npm install puppeteer-core` to install it. Find out more in the [Automation Protocols](/docs/automationProtocols.md) section.

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

```
await browser.throttleNetwork({ offline, latency, downloadThroughput, uploadThroughput })
```

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

| Name                        | Type              | Details                                                                              |
| --------------------------- | ----------------- | ------------------------------------------------------------------------------------ |
| `params`                    | `ThrottleOptions` | parameters for throttling                                                            |
| `params.offline`            | `boolean`         | True to emulate internet disconnection.                                              |
| `params.latency`            | `number`          | Minimum latency from request sent to response headers received (ms).                 |
| `params.downloadThroughput` | `number`          | Maximal aggregated download throughput (bytes/sec). -1 disables download throttling. |
| `params.uploadThroughput`   | `number`          | Maximal aggregated upload throughput (bytes/sec). -1 disables upload throttling.     |

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

throttleNetwork.js

```
it('should throttle the network', async () => {
    // via static string preset
    await browser.throttleNetwork('Regular3G')

    // via custom values
    await browser.throttleNetwork({
        offline: false,
        downloadThroughput: 200 * 1024 / 8,
        uploadThroughput: 200 * 1024 / 8,
        latency: 20
    })
});
```
