Created
July 22, 2023 15:32
-
-
Save andreasneuber/2b574a6711a8e5f3fe31d6cb7e85bdf5 to your computer and use it in GitHub Desktop.
Throttle network speed via Playwright CDPSession
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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