Node.js headless browser that can intercept HTTP request data?

I need help with web scraping automation. There’s a site I’m working with that generates a special token through some complex JavaScript code. This token gets added to HTTP requests as a parameter but it’s not saved in cookies or visible on the page itself.

When I check the network traffic, I can see this token is consistent across requests. I need to capture this token value from the outgoing HTTP calls made by a headless browser.

I tried looking into some browser automation tools but I’m not sure which one would let me monitor the actual request data being sent. Has anyone dealt with something similar before? What’s the best approach to intercept and read the request body content from a headless browser in Node.js?

Playwright’s another solid choice here. I’ve used it tons for token extraction and it handles HTTP monitoring really well. Unlike Puppeteer’s interception, Playwright lets you tap into network events without actually intercepting requests - keeps things running smoother. You can use page.route() for full interception or page.on('request') just to monitor without blocking. The request object has everything you need - headers, post body, all of it. Best part is it supports multiple browser engines. If token generation breaks in Chromium, just switch to Firefox or WebKit. Network monitoring’s been way more reliable for me on complex JS-heavy sites too.

selenium-wire’s worth a look if you want something different. It’s basically selenium webdriver with built-in request/response capture. Setup’s straightforward and you don’t need to mess with interception APIs. Just run your browser automation normally and check driver.requests to see all HTTP traffic. Works great for grabbing tokens from XHR calls without hitting performance much.

Puppeteer handles this pretty well with request interception. Enable it and you’ll get full request details - headers, POST data, URL parameters, everything. I’ve used this for dynamic tokens that get injected through JavaScript execution. Set up page.setRequestInterception(true) then use page.on('request') to catch outgoing requests. Extract whatever token data you need from the request object. One heads up - intercepting requests can really slow down page loading. Filter for specific URLs or request types if performance becomes an issue. The request object gives you method, URL, headers, and postData properties, which covers most token extraction needs.