Skip to content

[Please read the message below]Why can't we keep monitoring the response? #2845

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task done
bbhxwl opened this issue May 8, 2025 · 6 comments
Closed
1 task done

Comments

@bbhxwl
Copy link

bbhxwl commented May 8, 2025

Please do not submit this issue.

  • I understand
@bbhxwl
Copy link
Author

bbhxwl commented May 8, 2025

from playwright.sync_api import sync_playwright
import time


def main():
    with sync_playwright() as p:
        browser = p.chromium.launch(headless=False)
        page = browser.new_page()
        def response(response):
            print("url", response.request.method, response.url)

        page.on("response", response)
        page.goto("https://google.com")
        try:
            while True:
                time.sleep(1)
        except KeyboardInterrupt:
            print("q")


if __name__ == "__main__":
    main()

@bbhxwl
Copy link
Author

bbhxwl commented May 8, 2025

Refresh the page, he will no longer listen for any requests.

@mxschmitt
Copy link
Member

Probably related to this: https://playwright.dev/python/docs/library#timesleep-leads-to-outdated-state

Try to use page.wait_for_timeout(1000) instead.

@bbhxwl
Copy link
Author

bbhxwl commented May 9, 2025

Probably related to this: https://playwright.dev/python/docs/library#timesleep-leads-to-outdated-state

Try to use page.wait_for_timeout(1000) instead.

Thank you, I tested it and it can solve my problem. I just need to wait for a long time, right?

@mxschmitt
Copy link
Member

Yes.

@bbhxwl
Copy link
Author

bbhxwl commented May 10, 2025

Yes.

But in the future, he won't continue to execute the code behind me, right? If I wait for a short time and he executes my final code, the program will automatically shut down. How should this be resolved?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants