|
| 1 | +--- |
| 2 | +title: 'throttleNetwork(networkProfile)' |
| 3 | +excerpt: 'Browser module: page.throttleNetwork(networkProfile) method' |
| 4 | +--- |
| 5 | + |
| 6 | +# throttleNetwork(networkProfile) |
| 7 | + |
| 8 | +Throttles the network in Chrome/Chromium to slow it down by the specified fields in the `networkProfile` object. |
| 9 | + |
| 10 | +| Parameter | Type | Default | Description | |
| 11 | +|-------------------------|----------------|---------|----------------------------------------------------------------------------------------| |
| 12 | +| networkProfile | NetworkProfile | `null` | This is a mandatory parameter. | |
| 13 | +| networkProfile.latency | number | `0` | Minimum latency from request sent to response headers received (ms). | |
| 14 | +| networkProfile.download | number | `-1` | Maximal aggregated download throughput (bytes/sec). `-1` disables download throttling. | |
| 15 | +| networkProfile.upload | number | `-1` | Maximal aggregated upload throughput (bytes/sec). `-1` disables upload throttling. | |
| 16 | + |
| 17 | +To work with the most commonly tested network profiles, import `networkProfiles` from the browser module. There are three profiles available: |
| 18 | + |
| 19 | +| Name | Notes | |
| 20 | +|-------------------|--------------------------------------------------------------------------------------------------------------------------------| |
| 21 | +| `'No Throttling'` | No throttling, which is the default before applying any network throttling. This can be used to remove the network throttling. | |
| 22 | +| `'Fast 3G'` | Emulates a typical fast 3G connection | |
| 23 | +| `'Slow 3G'` | Emulates a typical slow 3G connection | |
| 24 | + |
| 25 | +### Example |
| 26 | + |
| 27 | +{{< code >}} |
| 28 | + |
| 29 | +```javascript |
| 30 | +import { browser, networkProfiles } from 'k6/x/browser'; |
| 31 | + |
| 32 | +export const options = { |
| 33 | + scenarios: { |
| 34 | + browser: { |
| 35 | + executor: 'shared-iterations', |
| 36 | + options: { |
| 37 | + browser: { |
| 38 | + type: 'chromium', |
| 39 | + }, |
| 40 | + }, |
| 41 | + }, |
| 42 | + }, |
| 43 | +}; |
| 44 | + |
| 45 | +export default async function () { |
| 46 | + const context = browser.newContext(); |
| 47 | + const page = context.newPage(); |
| 48 | + |
| 49 | + try { |
| 50 | + page.throttleNetwork(networkProfiles['Slow 3G']); |
| 51 | + |
| 52 | + await page.goto('https://test.k6.io/', { waitUntil: 'networkidle' }); |
| 53 | + } finally { |
| 54 | + page.close(); |
| 55 | + } |
| 56 | +} |
| 57 | +``` |
| 58 | + |
| 59 | +{{< /code >}} |
0 commit comments