You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Question] Does playwright support browser network emulation? #3393
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.
const{chromium}=require('playwright');(async()=>{constbrowser=awaitchromium.launch();constcontext=awaitbrowser.newContext();constpage=awaitcontext.newPage();constcdp=awaitcontext.newCDPSession(page);// Set throttling propertyawaitcdp.send('Network.emulateNetworkConditions',{'offline': false,'downloadThroughput': 200*1024/8,'uploadThroughput': 200*1024/8,'latency': 20});// Go on with the throttled page...awaitpage.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.
Activity
aslushnikov commentedon Aug 12, 2020
Venkatesh Devale (@devalevenkatesh) Puppeteer's network throttling is done using Chrome DevTool Protocol; you can do the same with chromium in Playwright using
context.newCDPSession():This method, however, has a few downsides:
To throttle "for real", we'd recommend user-land solutions:
tc. wondershaper is a convenience wrapper atop oftcand might be a good starting point.Hope this helps!