You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: Python sync API logs CancelledError when exiting sync_playwright() with an unanswered route #3266
importloggingfromplaywright.sync_apiimportsync_playwrightlogging.basicConfig(level=logging.ERROR)
held= []
withsync_playwright() asp:
browser=p.chromium.launch()
page=browser.new_page()
page.route("**/held", lambdaroute: held.append(route)) # hold, never answerpage.set_content("<p>x</p>")
page.evaluate("() => { fetch('http://example.test/held').catch(() => {}); }")
page.wait_for_timeout(500)
browser.close()
# Exiting the with block cancels pending tasks in Playwright's own event loop.
Expected behavior
A route handler task that is still pending when exiting with sync_playwright() gets cancelled without an error being logged. Cancelling pending tasks during context-manager shutdown is the behavior microsoft/playwright-python#1430 introduced while fixing microsoft/playwright-python#1402.
Actual behavior
During context-manager shutdown, asyncio logs an error from Playwright's own done callback:
ERROR:asyncio:Exception in callback Connection.dispatch.<locals>._done_callback(<Task cancell..._page.py:298>>) at .../playwright/_impl/_connection.py:546
handle: <Handle Connection.dispatch.<locals>._done_callback(<Task cancell..._page.py:298>>) at .../playwright/_impl/_connection.py:546>
Traceback (most recent call last):
File "/usr/lib/python3.12/asyncio/events.py", line 88, in _run
self._context.run(self._callback, *self._args)
File ".../playwright/_impl/_connection.py", line 547, in _done_callback
exc = future.exception()
^^^^^^^^^^^^^^^^^^
File ".../playwright/_impl/_page.py", line 312, in _on_route
handled = await route_handler.handle(route)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../playwright/_impl/_helper.py", line 443, in handle
return await self._handle_internal(route)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../playwright/_impl/_helper.py", line 485, in _handle_internal
return await handled_future
^^^^^^^^^^^^^^^^^^^^
asyncio.exceptions.CancelledError
Additional context
No response
Environment
- Operating System: Ubuntu 24.04.3 LTS (Linux 6.8.0-101-generic x86_64)
- CPU: x86_64, 8 cores
- Browser: Chromium 156.0.8078.4 (bundled with playwright 1.64.0, headless)
- Python Version: 3.12.3
- Other info: sync API
Also repro'd on Windows:
- Windows, Python 3.12.10
- Playwright 1.64.0
- Bundled headless Chromium 156.0.8078.4
Hi, the Playwright bot looked into this on my behalf.
This matches #3272 and is already fixed on main, but not yet released. The same pending-route reproduction produces CancelledError in 1.63.0 and 1.64.0, and stays quiet on main after #3280.
The full reproduction and checks are in #3272 (comment). Those checks covered all three browsers on macOS 27.0.1 arm64 with Python 3.14.6, including headed and headless runs on main and verification of the fix commit against its parent. Linux, Windows and Python 3.12 were not checked locally.
Activity
dcrousso commentedon Oct 21, 2026
Hi, the Playwright bot looked into this on my behalf.
This matches #3272 and is already fixed on main, but not yet released. The same pending-route reproduction produces
CancelledErrorin 1.63.0 and 1.64.0, and stays quiet on main after #3280.The full reproduction and checks are in #3272 (comment). Those checks covered all three browsers on macOS 27.0.1 arm64 with Python 3.14.6, including headed and headless runs on main and verification of the fix commit against its parent. Linux, Windows and Python 3.12 were not checked locally.