Skip to content

Instantly share code, notes, and snippets.

@hugoeanogueira
Created January 11, 2024 09:44
Show Gist options
  • Save hugoeanogueira/1bbd3251f3d169fc4901e4abcf640755 to your computer and use it in GitHub Desktop.
Save hugoeanogueira/1bbd3251f3d169fc4901e4abcf640755 to your computer and use it in GitHub Desktop.
Configure Network and CPU throttling to Chrome using Playwright
// ENABLE THROTTLING IN CHROME WITH PLAYWRIGHT
// https://chromedevtools.github.io/devtools-protocol/tot/Network/#method-emulateNetworkConditions
// https://chromedevtools.github.io/devtools-protocol/tot/Emulation/#method-setCPUThrottlingRate
const cdpSession = await context.newCDPSession(page);
await cdpSession.send("Network.emulateNetworkConditions", {
downloadThroughput: 2_000_000 / 8, // 2 mbps
uploadThroughput: 2_000_000 / 8, // 2 mbps
latency: 100, // 100 ms
offline: false,
});
await cdpSession.send("Emulation.setCPUThrottlingRate", {
rate: 2 // 2x cpu throttle
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment