throttleCPU
Overview
Apply a CPU slowdown through Chrome DevTools Protocol. Use this to exercise a page under reduced processing speed, not to reproduce a particular physical device.
Usage
browser.throttleCPU(factor)
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
factor | number | Required | Slowdown factor: 1 disables throttling, 2 requests a twofold slowdown. |
Result
Promise<void>.
Limitations
Requires Chromium and an available Puppeteer/CDP connection. The current implementation targets the first page returned by Puppeteer, not necessarily the active Testplane page. For this example, use one tab, isolation: false and testsPerSession: 1; a fresh session preserves test isolation. A non-number or an unavailable CDP connection causes an error. Factor 1 requests the normal CPU mode.
Example
Set baseUrl to your local HTTP test site, where / returns an HTML page. Run the example in a regular Testplane test file.
const assert = require("node:assert/strict");
it("throttleCPU: run a page with a slower CPU", async ({ browser }) => {
await browser.url("/");
try {
await browser.throttleCPU(2);
await browser.execute(() => {
document.body.innerHTML = "<button>Ready</button>";
});
assert.equal(await browser.$("button").getText(), "Ready");
} finally {
await browser.throttleCPU(1);
}
});