← Back to Discord Forum

Capture all XHR requests from a React application

iexistthereforeithinkposted in #help-playwright
Open in Discord

I am trying to capture all XHR requests from a React application, but the page closes before the entire page is rendered and all the XHR requests are fired.

Here is the code I am using:

from playwright.sync_api import sync_playwright, expect
        with sync_playwright() as pw:
            chromium = pw.chromium
            browser = chromium.launch()
            page = browser.new_page()
            page.on("request", lambda req: print(
                req.method, req.url, req.all_headers))

The page fires a few XHR requests after hydration, and I need to wait till it's completely hydrated.

Alternatively, I need to wait till an XHR request is made to a specific url.

This thread is trying to answer question "How to capture all XHR requests from a React application using Playwright in Python?"

1 reply

Its impossible to wait for all the network requests from a web application, since you never know what is all. You can wait for individual requests see here: https://playwright.dev/python/docs/network#network-events

with expect_response

AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

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 luc@ray.run.