How to monitor particular HTTP responses in Puppeteer?

I’ve been working with Puppeteer for browser automation and I’m stuck on something. I need to capture and handle a particular network response instead of getting flooded with every single request that happens on the page.

Right now when I use the response and requestfinish events, I get every response from the page like images, CSS files, and other resources. This makes it really hard to find the specific API call I’m interested in.

Is there a way to filter responses or listen only for the one I care about? I want to perform some actions based on that specific response data.

you can filter responses by checking the url inside the event handler. just do something like page.on('response', async response => { if (response.url().includes('your-api-endpoint')) { // handle your specific response } }) works great for me when i need to catch specific api calls without all the noise

Another approach is using page.waitForResponse() which waits for a specific response to occur. This method is particularly useful when you know exactly when the request should happen. You can pass a URL pattern or a predicate function to match your target response. For example await page.waitForResponse(response => response.url().endsWith('/api/data') && response.status() === 200) will wait until that specific endpoint returns successfully. This eliminates the need to listen to all responses and gives you more control over timing. I found this especially helpful when dealing with single-page applications where you need to wait for specific data to load before proceeding with automation tasks.

I had similar issues and found that combining request interception with response filtering works really well. Set up page.setRequestInterception(true) and then use page.on('request', ...) to tag the requests you care about, maybe by storing their URLs in a Set. Then in your response handler you can check if the response URL matches one from your tracked requests. This way you’re only processing responses for requests you explicitly marked as important. The performance improvement is noticeable especially on heavy pages with lots of assets. Just remember to call request.continue() for all requests in your request handler or the page will hang.