diff --git a/playwright/_impl/_network.py b/playwright/_impl/_network.py index 0230c2dba..cf10bbebf 100644 --- a/playwright/_impl/_network.py +++ b/playwright/_impl/_network.py @@ -290,6 +290,8 @@ async def _race_with_page_close(self, future: Coroutine) -> None: [fut, page._closed_or_crashed_future], return_when=asyncio.FIRST_COMPLETED, ) + if fut.done() and fut.exception(): + raise cast(BaseException, fut.exception()) if page._closed_or_crashed_future.done(): await asyncio.gather(fut, return_exceptions=True) else: diff --git a/tests/async/test_request_continue.py b/tests/async/test_request_continue.py index 7a6eb322b..f56adb7bd 100644 --- a/tests/async/test_request_continue.py +++ b/tests/async/test_request_continue.py @@ -88,6 +88,21 @@ async def test_should_override_request_url(page, server): assert (await request).method == b"GET" +async def test_should_raise_except(page, server): + exc_fut = asyncio.Future() + + async def capture_exception(route): + try: + await route.continue_(url="file:///tmp/does-not-exist") + exc_fut.set_result(None) + except Exception as e: + exc_fut.set_result(e) + + await page.route("**/*", capture_exception) + asyncio.create_task(page.goto(server.EMPTY_PAGE)) + assert "New URL must have same protocol as overridden URL" in str(await exc_fut) + + async def test_should_amend_utf8_post_data(page, server): await page.goto(server.EMPTY_PAGE) await page.route(