From db6014206b1b6981275d7bfb21de49cad11f6d2d Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Wed, 13 Aug 2025 13:49:52 +0200 Subject: [PATCH 1/2] fix: timeout option support with fetch api --- playwright/_impl/_fetch.py | 1 + tests/async/test_fetch_global.py | 11 +++++++++++ tests/sync/test_fetch_global.py | 11 +++++++++++ 3 files changed, 23 insertions(+) diff --git a/playwright/_impl/_fetch.py b/playwright/_impl/_fetch.py index e4174ea27..50bf4ad4a 100644 --- a/playwright/_impl/_fetch.py +++ b/playwright/_impl/_fetch.py @@ -412,6 +412,7 @@ async def _inner_fetch( self._timeout_settings.timeout, { "url": url, + "timeout": timeout, "params": object_to_array(params) if isinstance(params, dict) else None, "encodedParams": params if isinstance(params, str) else None, "method": method, diff --git a/tests/async/test_fetch_global.py b/tests/async/test_fetch_global.py index e2a7678c5..58bb4e2fe 100644 --- a/tests/async/test_fetch_global.py +++ b/tests/async/test_fetch_global.py @@ -89,6 +89,17 @@ async def test_should_support_global_timeout_option( await request.get(server.EMPTY_PAGE) +async def test_should_support_timeout_option_in_get_method( + playwright: Playwright, server: Server +) -> None: + request = await playwright.request.new_context() + server.set_route("/empty.html", lambda req: None) + with pytest.raises( + Error, match="APIRequestContext.get: Request timed out after 123ms" + ): + await request.get(server.EMPTY_PAGE, timeout=123) + + async def test_should_propagate_extra_http_headers_with_redirects( playwright: Playwright, server: Server ) -> None: diff --git a/tests/sync/test_fetch_global.py b/tests/sync/test_fetch_global.py index bf3970c21..2ce28c37f 100644 --- a/tests/sync/test_fetch_global.py +++ b/tests/sync/test_fetch_global.py @@ -71,6 +71,17 @@ def test_should_support_global_timeout_option( request.get(server.EMPTY_PAGE) +def test_should_support_timeout_option_in_get_method( + playwright: Playwright, server: Server +) -> None: + request = playwright.request.new_context() + server.set_route("/empty.html", lambda req: None) + with pytest.raises( + Error, match="APIRequestContext.get: Request timed out after 123ms" + ): + request.get(server.EMPTY_PAGE, timeout=123) + + def test_should_propagate_extra_http_headers_with_redirects( playwright: Playwright, server: Server ) -> None: From 3a385bb61eebde07a7d7edd06d749631cf523707 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Thu, 14 Aug 2025 13:06:06 +0200 Subject: [PATCH 2/2] test fixes --- tests/async/test_fetch_global.py | 4 +--- tests/async/test_page_request_intercept.py | 2 +- tests/sync/test_fetch_global.py | 4 +--- tests/sync/test_page_request_intercept.py | 2 +- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/tests/async/test_fetch_global.py b/tests/async/test_fetch_global.py index 58bb4e2fe..1f7593194 100644 --- a/tests/async/test_fetch_global.py +++ b/tests/async/test_fetch_global.py @@ -94,9 +94,7 @@ async def test_should_support_timeout_option_in_get_method( ) -> None: request = await playwright.request.new_context() server.set_route("/empty.html", lambda req: None) - with pytest.raises( - Error, match="APIRequestContext.get: Request timed out after 123ms" - ): + with pytest.raises(Error, match="APIRequestContext.get: Timeout 123ms exceeded."): await request.get(server.EMPTY_PAGE, timeout=123) diff --git a/tests/async/test_page_request_intercept.py b/tests/async/test_page_request_intercept.py index dc8f7416a..a9859e87b 100644 --- a/tests/async/test_page_request_intercept.py +++ b/tests/async/test_page_request_intercept.py @@ -34,7 +34,7 @@ def _handler(request: TestServerRequest) -> None: async def handle(route: Route) -> None: with pytest.raises(Error) as error: await route.fetch(timeout=1000) - assert "Timeout 1000ms exceeded" in error.value.message + assert "Route.fetch: Timeout 1000ms exceeded." in error.value.message await page.route("**/*", lambda route: handle(route)) with pytest.raises(Error) as error: diff --git a/tests/sync/test_fetch_global.py b/tests/sync/test_fetch_global.py index 2ce28c37f..5cb3abc5b 100644 --- a/tests/sync/test_fetch_global.py +++ b/tests/sync/test_fetch_global.py @@ -76,9 +76,7 @@ def test_should_support_timeout_option_in_get_method( ) -> None: request = playwright.request.new_context() server.set_route("/empty.html", lambda req: None) - with pytest.raises( - Error, match="APIRequestContext.get: Request timed out after 123ms" - ): + with pytest.raises(Error, match="APIRequestContext.get: Timeout 123ms exceeded."): request.get(server.EMPTY_PAGE, timeout=123) diff --git a/tests/sync/test_page_request_intercept.py b/tests/sync/test_page_request_intercept.py index 86cf21b63..1d3dd0f46 100644 --- a/tests/sync/test_page_request_intercept.py +++ b/tests/sync/test_page_request_intercept.py @@ -34,7 +34,7 @@ def _handle(request: TestServerRequest) -> None: def handle(route: Route) -> None: with pytest.raises(Error) as error: route.fetch(timeout=1000) - assert "Request timed out after 1000ms" in error.value.message + assert "Route.fetch: Timeout 1000ms exceeded." in error.value.message page.route("**/*", lambda route: handle(route)) with pytest.raises(Error) as error: