I’m working on end-to-end tests using Puppeteer and need to simulate different network conditions. Does anyone know if there’s a way to access the DevTools Network API through Puppeteer?
I’ve tried using chrome-remote-interface, but it’s not user-friendly enough for my needs. Puppeteer doesn’t seem to have built-in support for network emulation features like emulateNetworkConditions.
I’m wondering if there’s a workaround or a way to run JavaScript that can interact with the DevTools API in Puppeteer. Has anyone found a solution for this?
I’ve worked with the DevTools Network API using Puppeteer on a couple of projects. While Puppeteer doesn’t directly expose the network API, you can use a Chrome DevTools Protocol (CDP) session to tap into the functionality.
My method was to create a CDP session with the page:
This approach provided precise control over network scenarios. However, it’s wise to monitor Puppeteer updates since these internal CDP methods might evolve. For many cases, Puppeteer’s built-in emulateNetworkConditions remains a more stable alternative.
I’ve experimented with accessing the DevTools Network API using Puppeteer by creating a CDP session with page.target().createCDPSession().
After establishing the session, I enabled network features with Network.enable() and then used Network.emulateNetworkConditions to set parameters for latency, download, and upload speeds. This technique provides granular control over network simulation but depends on internal methods that may change in future versions. In my experience, using Puppeteer’s built-in emulateNetworkConditions offers a more stable approach for consistent testing.
then u can simulate different network stuff. it works pretty good but might break later so watch out lol. puppeteer’s built-in network stuff is prolly safer if u don’t need anything fancy