Skip to content

Instantly share code, notes, and snippets.

@andreasneuber
Created July 22, 2023 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreasneuber/2b574a6711a8e5f3fe31d6cb7e85bdf5 to your computer and use it in GitHub Desktop.
Save andreasneuber/2b574a6711a8e5f3fe31d6cb7e85bdf5 to your computer and use it in GitHub Desktop.
Throttle network speed via Playwright CDPSession
// See also https://chromedevtools.github.io/devtools-protocol/tot/Network/#method-emulateNetworkConditions
import { test, chromium } from '@playwright/test';
test("throttle network speed to 2.1 Mbps", async ({ }) => {
const browser = await chromium.launchPersistentContext("");
const page = await browser.newPage();
const client = await page.context().newCDPSession(page);
await client.send("Network.enable");
await client.send("Network.emulateNetworkConditions", {
offline: false,
downloadThroughput: (2 * 1024 * 1024) / 8,
uploadThroughput: (2 * 1024 * 1024) / 8,
latency: 70,
});
await page.goto("https://fast.com/");
await page.waitForTimeout(4000);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment