This thread is trying to answer question "How to intercept a network call and write the response to a JSON file, and how to handle multiple calls with the same name from a graphql url?"
If you want to listen for a single response: https://playwright.dev/docs/api/class-page#page-wait-for-response
Something like this
const responsePromise = page.waitForResponse('https://example.com/api/backend/call/endpoint'); await // your action to trigger the network call const response = await responsePromise; const content = await response.text(); fs.writeFileSync('networkResponse.txt', content);
@Reuvy check this out https://m.youtube.com/watch?v=SBPbjdXjT8A
Besides .waitForResponse there's also a .on('response'), which will keep handling response events for the life time of the context/page, from the moment you set it up.
It will make the execution non-linear though. It's less suitable for 'waiting for some specific response'. That's what waitForResponse is for. But if you want to record all the responses and at the end of the test you want to know all the responses received, then .on('response') could be used.
Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email firstname.lastname@example.org.