Skip to content

Commit 6e654db

Browse files
committed
Add browser module page. throttleNetwork doc
1 parent 00e3e55 commit 6e654db

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

docs/sources/next/javascript-api/k6-experimental/browser/page/_index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ Page provides methods to interact with a single tab in a running web browser. A
5858
| [page.tap(selector[, options])](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/page/tap/) | Taps the first element that matches the `selector`. |
5959
| [page.textContent(selector[, options])](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/page/textcontent/) | Returns the `element.textContent`. |
6060
| [page.throttleCPU(cpuProfile)](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/page/throttlecpu) | Throttles the CPU in Chrome/Chromium to slow it down by the specified `rate` in the `cpuProfile` object. |
61+
| [page.throttleNetwork(networkProfile)](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/page/throttlenetwork) | Throttles the network in Chrome/Chromium to slow it down by the specified fields in the `networkProfile` object. |
6162
| [page.title()](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/page/title) | Returns the `page`'s title. |
6263
| [page.type(selector, text[, options])](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/page/type/) | Types the `text` in the first element found that matches the `selector`. |
6364
| [page.touchScreen](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/page/touchscreen) | Returns the [Touchscreen](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/touchscreen) instance to interact with a virtual touchscreen on the page. |
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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

Comments
 (0)