Skip to content

Commit 0e3a502

Browse files
authored
fix: _race_with_page_close swallowed exception (#1379)
1 parent f742da9 commit 0e3a502

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

playwright/_impl/_network.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,8 @@ async def _race_with_page_close(self, future: Coroutine) -> None:
290290
[fut, page._closed_or_crashed_future],
291291
return_when=asyncio.FIRST_COMPLETED,
292292
)
293+
if fut.done() and fut.exception():
294+
raise cast(BaseException, fut.exception())
293295
if page._closed_or_crashed_future.done():
294296
await asyncio.gather(fut, return_exceptions=True)
295297
else:

tests/async/test_request_continue.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,21 @@ async def test_should_override_request_url(page, server):
8888
assert (await request).method == b"GET"
8989

9090

91+
async def test_should_raise_except(page, server):
92+
exc_fut = asyncio.Future()
93+
94+
async def capture_exception(route):
95+
try:
96+
await route.continue_(url="file:///tmp/does-not-exist")
97+
exc_fut.set_result(None)
98+
except Exception as e:
99+
exc_fut.set_result(e)
100+
101+
await page.route("**/*", capture_exception)
102+
asyncio.create_task(page.goto(server.EMPTY_PAGE))
103+
assert "New URL must have same protocol as overridden URL" in str(await exc_fut)
104+
105+
91106
async def test_should_amend_utf8_post_data(page, server):
92107
await page.goto(server.EMPTY_PAGE)
93108
await page.route(

0 commit comments

Comments
 (0)