Skip to content

Commit 00e3e55

Browse files
committed
Add browser module page.throttleCPU documentation
1 parent cf59f01 commit 00e3e55

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-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
@@ -57,6 +57,7 @@ Page provides methods to interact with a single tab in a running web browser. A
5757
| [page.setViewportSize(viewportSize)](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/page/setviewportsize) | Updates the `page`'s width and height. |
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`. |
60+
| [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. |
6061
| [page.title()](https://grafana.com/docs/k6/<K6_VERSION>/javascript-api/k6-experimental/browser/page/title) | Returns the `page`'s title. |
6162
| [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`. |
6263
| [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: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
title: 'throttleCPU(cpuProfile)'
3+
excerpt: 'Browser module: page.throttleCPU(cpuProfile) method'
4+
---
5+
6+
# throttleCPU(cpuProfile)
7+
8+
Throttles the CPU in Chrome/Chromium to slow it down by the specified `rate` in `cpuProfile`.
9+
10+
| Parameter | Type | Default | Description |
11+
|-----------------|------------|---------|----------------------------------------------------------------------|
12+
| cpuProfile | CPUProfile | `null` | This is a mandatory parameter. |
13+
| cpuProfile.rate | number | `1` | rate as a slowdown factor (1 is no throttle, 2 is 2x slowdown, etc). |
14+
15+
### Example
16+
17+
{{< code >}}
18+
19+
```javascript
20+
import { browser } from 'k6/experimental/browser';
21+
22+
export const options = {
23+
scenarios: {
24+
browser: {
25+
executor: 'shared-iterations',
26+
options: {
27+
browser: {
28+
type: 'chromium',
29+
},
30+
},
31+
},
32+
},
33+
};
34+
35+
export default async function () {
36+
const context = browser.newContext();
37+
const page = context.newPage();
38+
39+
try {
40+
page.throttleCPU({ rate: 4 });
41+
42+
await page.goto('https://test.k6.io/', { waitUntil: 'networkidle' });
43+
} finally {
44+
page.close();
45+
}
46+
}
47+
```
48+
49+
{{< /code >}}

0 commit comments

Comments
 (0)