Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Does playwright support browser network emulation? #3393

Closed
devalevenkatesh opened this issue Aug 11, 2020 · 1 comment
Closed

Comments

@devalevenkatesh
Copy link

devalevenkatesh commented Aug 11, 2020

I guess Puppeteer supports network emulation / throttling. I am looking for something similar using Playwright. I checked the API reference but did not found anything in Network section. Thanks for such a great library.

@aslushnikov
Copy link
Collaborator

@devalevenkatesh Puppeteer's network throttling is done using Chrome DevTool Protocol; you can do the same with chromium in Playwright using context.newCDPSession():

const {chromium} = require('playwright');

(async () => {
  const browser = await chromium.launch();
  const context = await browser.newContext();
  const page = await context.newPage();
  const cdp = await context.newCDPSession(page);
  // Set throttling property
  await cdp.send('Network.emulateNetworkConditions', {
    'offline': false,
    'downloadThroughput': 200 * 1024 / 8,
    'uploadThroughput': 200 * 1024 / 8,
    'latency': 20
  });
  // Go on with the throttled page...
  await page.goto('https://example.com');
})();

This method, however, has a few downsides:

  • will not work in other browsers in Playwright since there's no CDP
  • does not work ideally in Chromium either since webrtc and websockets are not throttled

To throttle "for real", we'd recommend user-land solutions:

  • Charles Proxy is quite popular and works across OS'es.
  • On Linux, network shaping could be configured per network interface with tools like tc. wondershaper is a convenience wrapper atop of tc and might be a good starting point.
  • On Mac, there's Network Link Conditioner.

Hope this helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants