Skip to content

[BUG] 'Request context disposed' was reported when use route.fetch() #23781

@erma0

Description

@erma0

Context:

  • Playwright Version: 1.35.0
  • Operating System: Windows 11
  • Python version: 3.11.2
  • Browser: Chromium-msedge
  • Extra:

Code Snippet

from playwright.sync_api import Route, sync_playwright


def handle(route: Route):
    res = route.fetch()
    route.fulfill(response=res)


with sync_playwright() as playwright:
    browser = playwright.chromium.launch(channel='msedge', headless=False)
    context = browser.new_context()
    page = context.new_page()

    page.route("**/*", handle)
    page.goto("https://www.baidu.com/", wait_until='domcontentloaded')
    page.unroute("**/*") # not work

    page.close()
    context.close()
    browser.close()

Describe the bug
'Request context disposed' or 'Response context disposed'

I think it's because the page has been closed, but the route handle function is still running.

It appears to be related to microsoft/playwright-python#1402 microsoft/playwright-python#1433 microsoft/playwright-python#1458 and has been fixed, but this issue still persists.

How can I stop a running route handle function before the page is closed?

thanks.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions