Skip to content
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

[BUG] asyncio.exceptions.CancelledError if all_headers() is called on failed request and page is reused (Chromium) #1575

Open
JannisBush opened this issue Sep 30, 2022 · 0 comments

Comments

@JannisBush
Copy link

Context:

  • Playwright Version: 1.26.0
  • Operating System: Mac
  • Python version: 3.9
  • Browser: Chromium

Code Snippet

  • Run python test.py for normal behavior: TimeoutError, {headers}, Error
  • Run python test.py fail for failing behavior: TimeoutError, {headers}, asyncio.Exception
    test.py:
import sys
from playwright.sync_api import sync_playwright

def check_request(request):
    try:
        print(request.headers)
        print(request.all_headers())  # Fails
        print(request.headers_array())  # Fails
    except Exception as e:
        print(e.__class__.__name__)

def run(playwright, fail):
    browser = playwright.chromium.launch()
    # browser = playwright.firefox.launch()  # requestfailed not called?
    context = browser.new_context()
    page = context.new_page()
    page.on("requestfailed", check_request)

    url = "http://example.com"
    try:
        page.goto(url, timeout=1)
    except Exception as e:
        print(e.__class__.__name__)
    if fail:
        page.goto(url)
    browser.close()

if __name__ == '__main__':
    with sync_playwright() as playwright:
        fail = len(sys.argv) > 1
        run(playwright, fail)

Describe the bug

The request.all_headers() and request.headers_array() methods stall if another request is done with the same page after an error. This results in an asyncio.exceptions.CancelledError at the end of the script.
If the methods are called on the last request of a page, an error is raised instead. I would expect to always receive the error (or the headers, as the normal request.headers works).

For Firefox and WebKit, the requestfailed event does not seem to be called for timedout requests, so the above code does not generate any errors for them.

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

No branches or pull requests

2 participants