Recipe
This recipe shows how to extract data directly from API responses by intercepting network requests. Use Playwright’s response listener withwithNetworkSettledWait (TypeScript) or wait_for_network_settled (Python).
TypeScript
How it works
- Set up response listener — Use
page.on("response", handler)to listen for network responses. - Filter by URL — Check if the response URL matches your target API endpoint.
- Capture the data — Parse the JSON response and store it.
- Navigate to the page — The listener captures API calls triggered during page load.