Closed
Description
Context:
- Playwright Version: [what Playwright version do you use?] 1.22.0, 1.23.1, 1.24.0
- Operating System: [e.g. Windows, Linux or Mac] macOS
- Python version: [e.g. 3.7, 3.9] 3.9
- Browser: [e.g. All, Chromium, Firefox, WebKit] Chrome
- Extra: [any specific details about your environment]
Code Snippet
Help us help you! Put down a short code snippet that illustrates your bug and
that we can run and debug locally.
from playwright.sync_api import sync_playwright
with sync_playwright() as playwright:
browser = playwright.chromium.launch(headless=False, channel='chrome')
try:
context = browser.new_context()
context.route('**/*.png', lambda route, _: route.abort(), times=1)
page = context.new_page()
page.goto('https://www.w3.org/Graphics/PNG/Alphatest.html')
print("123")
page.goto('https://www.w3.org/Graphics/PNG/Alphatest.html?123')
print("456")
page.goto('https://www.w3.org/Graphics/PNG/Alphatest.html?456')
finally:
browser.close()
Describe the bug
Add any other details about the problem here.
on Playwright 1.22.0:
$ poetry run python check.py
123
456
Task exception was never retrieved
future: <Task finished name='Task-14' coro=<Channel.send() done, defined at /Users/yusuke-iwaki/Library/Caches/pypoetry/virtualenvs/pl-py-Lb07ZA6Z-py3.9/lib/python3.9/site-packages/playwright/_impl/_connection.py:38> exception=Error('Route is already handled!')>
Traceback (most recent call last):
File "/Users/yusuke-iwaki/Library/Caches/pypoetry/virtualenvs/pl-py-Lb07ZA6Z-py3.9/lib/python3.9/site-packages/playwright/_impl/_connection.py", line 39, in send
return await self.inner_send(method, params, False)
File "/Users/yusuke-iwaki/Library/Caches/pypoetry/virtualenvs/pl-py-Lb07ZA6Z-py3.9/lib/python3.9/site-packages/playwright/_impl/_connection.py", line 63, in inner_send
result = next(iter(done)).result()
playwright._impl._api_types.Error: Route is already handled!
on Playwright 1.23.1, or 1.24.0:
$ poetry run python check.py
123
456
Task was destroyed but it is pending!
task: <Task pending name='Task-27' coro=<BrowserContext._disable_interception() running at /Users/yusuke-iwaki/Library/Caches/pypoetry/virtualenvs/pl-py-Lb07ZA6Z-py3.9/lib/python3.9/site-packages/playwright/_impl/_browser_context.py:359>>
/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py:667: RuntimeWarning: coroutine 'BrowserContext._disable_interception' was never awaited
self._ready.clear()
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
I think this problem can be fixed by adding _check_not_handled/_report_handled in Route#abort
like playwright-java or original JS version of Playwright.
async def abort(self, errorCode: str = None) -> None:
self._check_not_handled() # <-- add this
await self._race_with_page_close(
self._channel.send("abort", locals_to_params(locals()))
)
self._report_handled(True) # <-- add this
They are missed in #1376
Metadata
Metadata
Assignees
Labels
No labels