From 9e33d7277caa3cee99cb991e20df6476167cfa22 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Thu, 4 Nov 2021 01:11:28 +0100 Subject: [PATCH] feat(roll): roll Playwright 1.17.0-next-1635811939000 --- README.md | 2 +- playwright/_impl/_artifact.py | 3 +- playwright/_impl/_browser.py | 5 +-- playwright/_impl/_browser_context.py | 2 - playwright/_impl/_browser_type.py | 5 +-- playwright/_impl/_connection.py | 4 ++ playwright/_impl/_frame.py | 17 +++++-- playwright/_impl/_helper.py | 2 +- playwright/_impl/_page.py | 6 +-- playwright/_impl/_tracing.py | 18 ++++---- playwright/_impl/_video.py | 7 +-- playwright/async_api/_generated.py | 67 +++++++++++++++++----------- playwright/sync_api/_generated.py | 59 ++++++++++++++---------- setup.py | 6 +-- tests/async/test_navigation.py | 20 ++++++++- tests/async/test_wait_for_url.py | 9 ++++ tests/async/test_worker.py | 4 +- 17 files changed, 144 insertions(+), 92 deletions(-) diff --git a/README.md b/README.md index 6c23dab57..181b67385 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Playwright is a Python library to automate [Chromium](https://www.chromium.org/H | | Linux | macOS | Windows | | :--- | :---: | :---: | :---: | -| Chromium 97.0.4666.0 | ✅ | ✅ | ✅ | +| Chromium 97.0.4681.0 | ✅ | ✅ | ✅ | | WebKit 15.4 | ✅ | ✅ | ✅ | | Firefox 93.0 | ✅ | ✅ | ✅ | diff --git a/playwright/_impl/_artifact.py b/playwright/_impl/_artifact.py index 270783b74..ba71ac5dd 100644 --- a/playwright/_impl/_artifact.py +++ b/playwright/_impl/_artifact.py @@ -26,11 +26,10 @@ def __init__( self, parent: ChannelOwner, type: str, guid: str, initializer: Dict ) -> None: super().__init__(parent, type, guid, initializer) - self._is_remote = False self.absolute_path = initializer["absolutePath"] async def path_after_finished(self) -> Optional[pathlib.Path]: - if self._is_remote: + if self._connection.is_remote: raise Error( "Path is not available when using browser_type.connect(). Use save_as() to save a local copy." ) diff --git a/playwright/_impl/_browser.py b/playwright/_impl/_browser.py index 56fbe0c14..e406d1017 100644 --- a/playwright/_impl/_browser.py +++ b/playwright/_impl/_browser.py @@ -56,8 +56,7 @@ def __init__( self._browser_type = parent self._is_connected = True self._is_closed_or_closing = False - self._is_remote = False - self._is_connected_over_websocket = False + self._should_close_connection_on_close = False self._contexts: List[BrowserContext] = [] self._channel.on("close", lambda _: self._on_close()) @@ -169,7 +168,7 @@ async def close(self) -> None: except Exception as e: if not is_safe_close_error(e): raise e - if self._is_connected_over_websocket: + if self._should_close_connection_on_close: await self._connection.stop_async() @property diff --git a/playwright/_impl/_browser_context.py b/playwright/_impl/_browser_context.py index 8424bef43..95dcb0733 100644 --- a/playwright/_impl/_browser_context.py +++ b/playwright/_impl/_browser_context.py @@ -308,8 +308,6 @@ async def close(self) -> None: har = cast( Artifact, from_channel(await self._channel.send("harExport")) ) - if self.browser and self.browser._is_remote: - har._is_remote = True await har.save_as( cast(Dict[str, str], self._options["recordHar"])["path"] ) diff --git a/playwright/_impl/_browser_type.py b/playwright/_impl/_browser_type.py index 97d8ede3e..1bbe29a6f 100644 --- a/playwright/_impl/_browser_type.py +++ b/playwright/_impl/_browser_type.py @@ -157,7 +157,6 @@ async def connect_over_cdp( ) response = await self._channel.send_return_as_dict("connectOverCDP", params) browser = cast(Browser, from_channel(response["browser"])) - browser._is_remote = True default_context = cast( Optional[BrowserContext], @@ -187,6 +186,7 @@ async def connect( transport, self._connection._loop, ) + connection.mark_as_remote() connection._is_sync = self._connection._is_sync connection._loop.create_task(connection.run()) playwright_future = connection.playwright_future @@ -205,8 +205,7 @@ async def connect( pre_launched_browser = playwright._initializer.get("preLaunchedBrowser") assert pre_launched_browser browser = cast(Browser, from_channel(pre_launched_browser)) - browser._is_remote = True - browser._is_connected_over_websocket = True + browser._should_close_connection_on_close = True def handle_transport_close() -> None: for context in browser.contexts: diff --git a/playwright/_impl/_connection.py b/playwright/_impl/_connection.py index ec5b15e56..de5ecd572 100644 --- a/playwright/_impl/_connection.py +++ b/playwright/_impl/_connection.py @@ -162,6 +162,10 @@ def __init__( self._loop = loop self.playwright_future: asyncio.Future["Playwright"] = loop.create_future() self._error: Optional[BaseException] = None + self.is_remote = False + + def mark_as_remote(self) -> None: + self.is_remote = True async def run_as_sync(self) -> None: self._is_sync = True diff --git a/playwright/_impl/_frame.py b/playwright/_impl/_frame.py index 7943a339c..1b51389a6 100644 --- a/playwright/_impl/_frame.py +++ b/playwright/_impl/_frame.py @@ -183,7 +183,7 @@ async def continuation() -> Optional[Response]: if wait_until not in self._load_states: t = deadline - monotonic_time() if t > 0: - await self.wait_for_load_state(state=wait_until, timeout=t) + await self._wait_for_load_state_impl(state=wait_until, timeout=t) if "newDocument" in event and "request" in event["newDocument"]: request = from_channel(event["newDocument"]["request"]) return await request.response() @@ -199,7 +199,7 @@ async def wait_for_url( ) -> None: matcher = URLMatcher(self._page._browser_context._options.get("baseURL"), url) if matcher.matches(self.url): - await self.wait_for_load_state(state=wait_until, timeout=timeout) + await self._wait_for_load_state_impl(state=wait_until, timeout=timeout) return async with self.expect_navigation( url=url, wait_until=wait_until, timeout=timeout @@ -207,12 +207,21 @@ async def wait_for_url( pass async def wait_for_load_state( + self, + state: Literal["domcontentloaded", "load", "networkidle"] = None, + timeout: float = None, + ) -> None: + return await self._wait_for_load_state_impl(state, timeout) + + async def _wait_for_load_state_impl( self, state: DocumentLoadState = None, timeout: float = None ) -> None: if not state: state = "load" - if state not in ("load", "domcontentloaded", "networkidle"): - raise Error("state: expected one of (load|domcontentloaded|networkidle)") + if state not in ("load", "domcontentloaded", "networkidle", "commit"): + raise Error( + "state: expected one of (load|domcontentloaded|networkidle|commit)" + ) if state in self._load_states: return wait_helper = self._setup_navigation_wait_helper("wait_for_load_state", timeout) diff --git a/playwright/_impl/_helper.py b/playwright/_impl/_helper.py index 32662ffc4..ab8417adc 100644 --- a/playwright/_impl/_helper.py +++ b/playwright/_impl/_helper.py @@ -59,7 +59,7 @@ ColorScheme = Literal["dark", "light", "no-preference"] ForcedColors = Literal["active", "none"] ReducedMotion = Literal["no-preference", "reduce"] -DocumentLoadState = Literal["domcontentloaded", "load", "networkidle"] +DocumentLoadState = Literal["commit", "domcontentloaded", "load", "networkidle"] KeyboardModifier = Literal["Alt", "Control", "Meta", "Shift"] MouseButton = Literal["left", "middle", "right"] diff --git a/playwright/_impl/_page.py b/playwright/_impl/_page.py index 022cdb2de..4a5f78ab4 100644 --- a/playwright/_impl/_page.py +++ b/playwright/_impl/_page.py @@ -257,8 +257,6 @@ def _on_download(self, params: Any) -> None: url = params["url"] suggested_filename = params["suggestedFilename"] artifact = cast(Artifact, from_channel(params["artifact"])) - if self._browser_context._browser: - artifact._is_remote = self._browser_context._browser._is_remote self.emit( Page.Events.Download, Download(self, url, suggested_filename, artifact) ) @@ -477,7 +475,9 @@ async def reload( ) async def wait_for_load_state( - self, state: DocumentLoadState = None, timeout: float = None + self, + state: Literal["domcontentloaded", "load", "networkidle"] = None, + timeout: float = None, ) -> None: return await self._main_frame.wait_for_load_state(**locals_to_params(locals())) diff --git a/playwright/_impl/_tracing.py b/playwright/_impl/_tracing.py index b627978f4..8648d6d3b 100644 --- a/playwright/_impl/_tracing.py +++ b/playwright/_impl/_tracing.py @@ -48,21 +48,19 @@ async def stop(self, path: Union[pathlib.Path, str] = None) -> None: await self._channel.send("tracingStop") async def _do_stop_chunk(self, path: Union[pathlib.Path, str] = None) -> None: + result = await self._channel.send_return_as_dict( + "tracingStopChunk", + { + "save": bool(path), + "skipCompress": False, + }, + ) artifact = cast( Optional[Artifact], - from_nullable_channel( - await self._channel.send( - "tracingStopChunk", - { - "save": bool(path), - }, - ) - ), + from_nullable_channel(result.get("artifact")), ) if not artifact: return - if self._context._browser: - artifact._is_remote = self._context._browser._is_remote if path: await artifact.save_as(path) await artifact.delete() diff --git a/playwright/_impl/_video.py b/playwright/_impl/_video.py index c4e0447ee..8a9925ed1 100644 --- a/playwright/_impl/_video.py +++ b/playwright/_impl/_video.py @@ -28,10 +28,6 @@ def __init__(self, page: "Page") -> None: self._dispatcher_fiber = page._dispatcher_fiber self._page = page self._artifact_future = page._loop.create_future() - if page._browser_context and page._browser_context._browser: - self._is_remote = page._browser_context._browser._is_remote - else: - self._is_remote = False if page.is_closed(): self._page_closed() else: @@ -46,11 +42,10 @@ def _page_closed(self) -> None: def _artifact_ready(self, artifact: Artifact) -> None: if not self._artifact_future.done(): - artifact._is_remote = self._is_remote self._artifact_future.set_result(artifact) async def path(self) -> pathlib.Path: - if self._is_remote: + if self._page._connection.is_remote: raise Error( "Path is not available when using browserType.connect(). Use save_as() to save a local copy." ) diff --git a/playwright/async_api/_generated.py b/playwright/async_api/_generated.py index bd3d9e0e0..8557902e9 100644 --- a/playwright/async_api/_generated.py +++ b/playwright/async_api/_generated.py @@ -3021,7 +3021,7 @@ async def goto( url: str, *, timeout: float = None, - wait_until: Literal["domcontentloaded", "load", "networkidle"] = None, + wait_until: Literal["commit", "domcontentloaded", "load", "networkidle"] = None, referer: str = None ) -> typing.Optional["Response"]: """Frame.goto @@ -3054,11 +3054,12 @@ async def goto( changed by using the `browser_context.set_default_navigation_timeout()`, `browser_context.set_default_timeout()`, `page.set_default_navigation_timeout()` or `page.set_default_timeout()` methods. - wait_until : Union["domcontentloaded", "load", "networkidle", NoneType] + wait_until : Union["commit", "domcontentloaded", "load", "networkidle", NoneType] When to consider operation succeeded, defaults to `load`. Events can be either: - `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired. - `'load'` - consider operation to be finished when the `load` event is fired. - `'networkidle'` - consider operation to be finished when there are no network connections for at least `500` ms. + - `'commit'` - consider operation to be finished when network response is received and the document started loading. referer : Union[str, NoneType] Referer header value. If provided it will take preference over the referer header value set by `page.set_extra_http_headers()`. @@ -3081,7 +3082,7 @@ def expect_navigation( self, *, url: typing.Union[str, typing.Pattern, typing.Callable[[str], bool]] = None, - wait_until: Literal["domcontentloaded", "load", "networkidle"] = None, + wait_until: Literal["commit", "domcontentloaded", "load", "networkidle"] = None, timeout: float = None ) -> AsyncEventContextManager["Response"]: """Frame.expect_navigation @@ -3108,11 +3109,12 @@ def expect_navigation( A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation. Note that if the parameter is a string without wilcard characters, the method will wait for navigation to URL that is exactly equal to the string. - wait_until : Union["domcontentloaded", "load", "networkidle", NoneType] + wait_until : Union["commit", "domcontentloaded", "load", "networkidle", NoneType] When to consider operation succeeded, defaults to `load`. Events can be either: - `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired. - `'load'` - consider operation to be finished when the `load` event is fired. - `'networkidle'` - consider operation to be finished when there are no network connections for at least `500` ms. + - `'commit'` - consider operation to be finished when network response is received and the document started loading. timeout : Union[float, NoneType] Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the `browser_context.set_default_navigation_timeout()`, @@ -3134,7 +3136,7 @@ async def wait_for_url( self, url: typing.Union[str, typing.Pattern, typing.Callable[[str], bool]], *, - wait_until: Literal["domcontentloaded", "load", "networkidle"] = None, + wait_until: Literal["commit", "domcontentloaded", "load", "networkidle"] = None, timeout: float = None ) -> NoneType: """Frame.wait_for_url @@ -3152,11 +3154,12 @@ async def wait_for_url( A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation. Note that if the parameter is a string without wilcard characters, the method will wait for navigation to URL that is exactly equal to the string. - wait_until : Union["domcontentloaded", "load", "networkidle", NoneType] + wait_until : Union["commit", "domcontentloaded", "load", "networkidle", NoneType] When to consider operation succeeded, defaults to `load`. Events can be either: - `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired. - `'load'` - consider operation to be finished when the `load` event is fired. - `'networkidle'` - consider operation to be finished when there are no network connections for at least `500` ms. + - `'commit'` - consider operation to be finished when network response is received and the document started loading. timeout : Union[float, NoneType] Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the `browser_context.set_default_navigation_timeout()`, @@ -3863,7 +3866,7 @@ async def set_content( html: str, *, timeout: float = None, - wait_until: Literal["domcontentloaded", "load", "networkidle"] = None + wait_until: Literal["commit", "domcontentloaded", "load", "networkidle"] = None ) -> NoneType: """Frame.set_content @@ -3876,11 +3879,12 @@ async def set_content( changed by using the `browser_context.set_default_navigation_timeout()`, `browser_context.set_default_timeout()`, `page.set_default_navigation_timeout()` or `page.set_default_timeout()` methods. - wait_until : Union["domcontentloaded", "load", "networkidle", NoneType] + wait_until : Union["commit", "domcontentloaded", "load", "networkidle", NoneType] When to consider operation succeeded, defaults to `load`. Events can be either: - `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired. - `'load'` - consider operation to be finished when the `load` event is fired. - `'networkidle'` - consider operation to be finished when there are no network connections for at least `500` ms. + - `'commit'` - consider operation to be finished when network response is received and the document started loading. """ return mapping.from_maybe_impl( @@ -5679,8 +5683,10 @@ def on( ```py async def print_args(msg): + values = [] for arg in msg.args: - print(await arg.json_value()) + values.append(await arg.json_value()) + print(values) page.on(\"console\", print_args) await page.evaluate(\"console.log('hello', 5, {foo: 'bar'})\") @@ -5928,8 +5934,10 @@ def once( ```py async def print_args(msg): + values = [] for arg in msg.args: - print(await arg.json_value()) + values.append(await arg.json_value()) + print(values) page.on(\"console\", print_args) await page.evaluate(\"console.log('hello', 5, {foo: 'bar'})\") @@ -7233,7 +7241,7 @@ async def set_content( html: str, *, timeout: float = None, - wait_until: Literal["domcontentloaded", "load", "networkidle"] = None + wait_until: Literal["commit", "domcontentloaded", "load", "networkidle"] = None ) -> NoneType: """Page.set_content @@ -7246,11 +7254,12 @@ async def set_content( changed by using the `browser_context.set_default_navigation_timeout()`, `browser_context.set_default_timeout()`, `page.set_default_navigation_timeout()` or `page.set_default_timeout()` methods. - wait_until : Union["domcontentloaded", "load", "networkidle", NoneType] + wait_until : Union["commit", "domcontentloaded", "load", "networkidle", NoneType] When to consider operation succeeded, defaults to `load`. Events can be either: - `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired. - `'load'` - consider operation to be finished when the `load` event is fired. - `'networkidle'` - consider operation to be finished when there are no network connections for at least `500` ms. + - `'commit'` - consider operation to be finished when network response is received and the document started loading. """ return mapping.from_maybe_impl( @@ -7267,7 +7276,7 @@ async def goto( url: str, *, timeout: float = None, - wait_until: Literal["domcontentloaded", "load", "networkidle"] = None, + wait_until: Literal["commit", "domcontentloaded", "load", "networkidle"] = None, referer: str = None ) -> typing.Optional["Response"]: """Page.goto @@ -7304,11 +7313,12 @@ async def goto( changed by using the `browser_context.set_default_navigation_timeout()`, `browser_context.set_default_timeout()`, `page.set_default_navigation_timeout()` or `page.set_default_timeout()` methods. - wait_until : Union["domcontentloaded", "load", "networkidle", NoneType] + wait_until : Union["commit", "domcontentloaded", "load", "networkidle", NoneType] When to consider operation succeeded, defaults to `load`. Events can be either: - `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired. - `'load'` - consider operation to be finished when the `load` event is fired. - `'networkidle'` - consider operation to be finished when there are no network connections for at least `500` ms. + - `'commit'` - consider operation to be finished when network response is received and the document started loading. referer : Union[str, NoneType] Referer header value. If provided it will take preference over the referer header value set by `page.set_extra_http_headers()`. @@ -7331,12 +7341,12 @@ async def reload( self, *, timeout: float = None, - wait_until: Literal["domcontentloaded", "load", "networkidle"] = None + wait_until: Literal["commit", "domcontentloaded", "load", "networkidle"] = None ) -> typing.Optional["Response"]: """Page.reload - Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of the - last redirect. + This method reloads the current page, in the same way as if the user had triggered a browser refresh. Returns the main + resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect. Parameters ---------- @@ -7345,11 +7355,12 @@ async def reload( changed by using the `browser_context.set_default_navigation_timeout()`, `browser_context.set_default_timeout()`, `page.set_default_navigation_timeout()` or `page.set_default_timeout()` methods. - wait_until : Union["domcontentloaded", "load", "networkidle", NoneType] + wait_until : Union["commit", "domcontentloaded", "load", "networkidle", NoneType] When to consider operation succeeded, defaults to `load`. Events can be either: - `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired. - `'load'` - consider operation to be finished when the `load` event is fired. - `'networkidle'` - consider operation to be finished when there are no network connections for at least `500` ms. + - `'commit'` - consider operation to be finished when network response is received and the document started loading. Returns ------- @@ -7418,7 +7429,7 @@ async def wait_for_url( self, url: typing.Union[str, typing.Pattern, typing.Callable[[str], bool]], *, - wait_until: Literal["domcontentloaded", "load", "networkidle"] = None, + wait_until: Literal["commit", "domcontentloaded", "load", "networkidle"] = None, timeout: float = None ) -> NoneType: """Page.wait_for_url @@ -7438,11 +7449,12 @@ async def wait_for_url( A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation. Note that if the parameter is a string without wilcard characters, the method will wait for navigation to URL that is exactly equal to the string. - wait_until : Union["domcontentloaded", "load", "networkidle", NoneType] + wait_until : Union["commit", "domcontentloaded", "load", "networkidle", NoneType] When to consider operation succeeded, defaults to `load`. Events can be either: - `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired. - `'load'` - consider operation to be finished when the `load` event is fired. - `'networkidle'` - consider operation to be finished when there are no network connections for at least `500` ms. + - `'commit'` - consider operation to be finished when network response is received and the document started loading. timeout : Union[float, NoneType] Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the `browser_context.set_default_navigation_timeout()`, @@ -7500,7 +7512,7 @@ async def go_back( self, *, timeout: float = None, - wait_until: Literal["domcontentloaded", "load", "networkidle"] = None + wait_until: Literal["commit", "domcontentloaded", "load", "networkidle"] = None ) -> typing.Optional["Response"]: """Page.go_back @@ -7516,11 +7528,12 @@ async def go_back( changed by using the `browser_context.set_default_navigation_timeout()`, `browser_context.set_default_timeout()`, `page.set_default_navigation_timeout()` or `page.set_default_timeout()` methods. - wait_until : Union["domcontentloaded", "load", "networkidle", NoneType] + wait_until : Union["commit", "domcontentloaded", "load", "networkidle", NoneType] When to consider operation succeeded, defaults to `load`. Events can be either: - `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired. - `'load'` - consider operation to be finished when the `load` event is fired. - `'networkidle'` - consider operation to be finished when there are no network connections for at least `500` ms. + - `'commit'` - consider operation to be finished when network response is received and the document started loading. Returns ------- @@ -7538,7 +7551,7 @@ async def go_forward( self, *, timeout: float = None, - wait_until: Literal["domcontentloaded", "load", "networkidle"] = None + wait_until: Literal["commit", "domcontentloaded", "load", "networkidle"] = None ) -> typing.Optional["Response"]: """Page.go_forward @@ -7554,11 +7567,12 @@ async def go_forward( changed by using the `browser_context.set_default_navigation_timeout()`, `browser_context.set_default_timeout()`, `page.set_default_navigation_timeout()` or `page.set_default_timeout()` methods. - wait_until : Union["domcontentloaded", "load", "networkidle", NoneType] + wait_until : Union["commit", "domcontentloaded", "load", "networkidle", NoneType] When to consider operation succeeded, defaults to `load`. Events can be either: - `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired. - `'load'` - consider operation to be finished when the `load` event is fired. - `'networkidle'` - consider operation to be finished when there are no network connections for at least `500` ms. + - `'commit'` - consider operation to be finished when network response is received and the document started loading. Returns ------- @@ -9379,7 +9393,7 @@ def expect_navigation( self, *, url: typing.Union[str, typing.Pattern, typing.Callable[[str], bool]] = None, - wait_until: Literal["domcontentloaded", "load", "networkidle"] = None, + wait_until: Literal["commit", "domcontentloaded", "load", "networkidle"] = None, timeout: float = None ) -> AsyncEventContextManager["Response"]: """Page.expect_navigation @@ -9409,11 +9423,12 @@ def expect_navigation( A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation. Note that if the parameter is a string without wilcard characters, the method will wait for navigation to URL that is exactly equal to the string. - wait_until : Union["domcontentloaded", "load", "networkidle", NoneType] + wait_until : Union["commit", "domcontentloaded", "load", "networkidle", NoneType] When to consider operation succeeded, defaults to `load`. Events can be either: - `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired. - `'load'` - consider operation to be finished when the `load` event is fired. - `'networkidle'` - consider operation to be finished when there are no network connections for at least `500` ms. + - `'commit'` - consider operation to be finished when network response is received and the document started loading. timeout : Union[float, NoneType] Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the `browser_context.set_default_navigation_timeout()`, diff --git a/playwright/sync_api/_generated.py b/playwright/sync_api/_generated.py index 7ac882cab..5f85dbd4a 100644 --- a/playwright/sync_api/_generated.py +++ b/playwright/sync_api/_generated.py @@ -2970,7 +2970,7 @@ def goto( url: str, *, timeout: float = None, - wait_until: Literal["domcontentloaded", "load", "networkidle"] = None, + wait_until: Literal["commit", "domcontentloaded", "load", "networkidle"] = None, referer: str = None ) -> typing.Optional["Response"]: """Frame.goto @@ -3003,11 +3003,12 @@ def goto( changed by using the `browser_context.set_default_navigation_timeout()`, `browser_context.set_default_timeout()`, `page.set_default_navigation_timeout()` or `page.set_default_timeout()` methods. - wait_until : Union["domcontentloaded", "load", "networkidle", NoneType] + wait_until : Union["commit", "domcontentloaded", "load", "networkidle", NoneType] When to consider operation succeeded, defaults to `load`. Events can be either: - `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired. - `'load'` - consider operation to be finished when the `load` event is fired. - `'networkidle'` - consider operation to be finished when there are no network connections for at least `500` ms. + - `'commit'` - consider operation to be finished when network response is received and the document started loading. referer : Union[str, NoneType] Referer header value. If provided it will take preference over the referer header value set by `page.set_extra_http_headers()`. @@ -3030,7 +3031,7 @@ def expect_navigation( self, *, url: typing.Union[str, typing.Pattern, typing.Callable[[str], bool]] = None, - wait_until: Literal["domcontentloaded", "load", "networkidle"] = None, + wait_until: Literal["commit", "domcontentloaded", "load", "networkidle"] = None, timeout: float = None ) -> EventContextManager["Response"]: """Frame.expect_navigation @@ -3057,11 +3058,12 @@ def expect_navigation( A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation. Note that if the parameter is a string without wilcard characters, the method will wait for navigation to URL that is exactly equal to the string. - wait_until : Union["domcontentloaded", "load", "networkidle", NoneType] + wait_until : Union["commit", "domcontentloaded", "load", "networkidle", NoneType] When to consider operation succeeded, defaults to `load`. Events can be either: - `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired. - `'load'` - consider operation to be finished when the `load` event is fired. - `'networkidle'` - consider operation to be finished when there are no network connections for at least `500` ms. + - `'commit'` - consider operation to be finished when network response is received and the document started loading. timeout : Union[float, NoneType] Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the `browser_context.set_default_navigation_timeout()`, @@ -3083,7 +3085,7 @@ def wait_for_url( self, url: typing.Union[str, typing.Pattern, typing.Callable[[str], bool]], *, - wait_until: Literal["domcontentloaded", "load", "networkidle"] = None, + wait_until: Literal["commit", "domcontentloaded", "load", "networkidle"] = None, timeout: float = None ) -> NoneType: """Frame.wait_for_url @@ -3101,11 +3103,12 @@ def wait_for_url( A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation. Note that if the parameter is a string without wilcard characters, the method will wait for navigation to URL that is exactly equal to the string. - wait_until : Union["domcontentloaded", "load", "networkidle", NoneType] + wait_until : Union["commit", "domcontentloaded", "load", "networkidle", NoneType] When to consider operation succeeded, defaults to `load`. Events can be either: - `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired. - `'load'` - consider operation to be finished when the `load` event is fired. - `'networkidle'` - consider operation to be finished when there are no network connections for at least `500` ms. + - `'commit'` - consider operation to be finished when network response is received and the document started loading. timeout : Union[float, NoneType] Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the `browser_context.set_default_navigation_timeout()`, @@ -3807,7 +3810,7 @@ def set_content( html: str, *, timeout: float = None, - wait_until: Literal["domcontentloaded", "load", "networkidle"] = None + wait_until: Literal["commit", "domcontentloaded", "load", "networkidle"] = None ) -> NoneType: """Frame.set_content @@ -3820,11 +3823,12 @@ def set_content( changed by using the `browser_context.set_default_navigation_timeout()`, `browser_context.set_default_timeout()`, `page.set_default_navigation_timeout()` or `page.set_default_timeout()` methods. - wait_until : Union["domcontentloaded", "load", "networkidle", NoneType] + wait_until : Union["commit", "domcontentloaded", "load", "networkidle", NoneType] When to consider operation succeeded, defaults to `load`. Events can be either: - `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired. - `'load'` - consider operation to be finished when the `load` event is fired. - `'networkidle'` - consider operation to be finished when there are no network connections for at least `500` ms. + - `'commit'` - consider operation to be finished when network response is received and the document started loading. """ return mapping.from_maybe_impl( @@ -7049,7 +7053,7 @@ def set_content( html: str, *, timeout: float = None, - wait_until: Literal["domcontentloaded", "load", "networkidle"] = None + wait_until: Literal["commit", "domcontentloaded", "load", "networkidle"] = None ) -> NoneType: """Page.set_content @@ -7062,11 +7066,12 @@ def set_content( changed by using the `browser_context.set_default_navigation_timeout()`, `browser_context.set_default_timeout()`, `page.set_default_navigation_timeout()` or `page.set_default_timeout()` methods. - wait_until : Union["domcontentloaded", "load", "networkidle", NoneType] + wait_until : Union["commit", "domcontentloaded", "load", "networkidle", NoneType] When to consider operation succeeded, defaults to `load`. Events can be either: - `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired. - `'load'` - consider operation to be finished when the `load` event is fired. - `'networkidle'` - consider operation to be finished when there are no network connections for at least `500` ms. + - `'commit'` - consider operation to be finished when network response is received and the document started loading. """ return mapping.from_maybe_impl( @@ -7083,7 +7088,7 @@ def goto( url: str, *, timeout: float = None, - wait_until: Literal["domcontentloaded", "load", "networkidle"] = None, + wait_until: Literal["commit", "domcontentloaded", "load", "networkidle"] = None, referer: str = None ) -> typing.Optional["Response"]: """Page.goto @@ -7120,11 +7125,12 @@ def goto( changed by using the `browser_context.set_default_navigation_timeout()`, `browser_context.set_default_timeout()`, `page.set_default_navigation_timeout()` or `page.set_default_timeout()` methods. - wait_until : Union["domcontentloaded", "load", "networkidle", NoneType] + wait_until : Union["commit", "domcontentloaded", "load", "networkidle", NoneType] When to consider operation succeeded, defaults to `load`. Events can be either: - `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired. - `'load'` - consider operation to be finished when the `load` event is fired. - `'networkidle'` - consider operation to be finished when there are no network connections for at least `500` ms. + - `'commit'` - consider operation to be finished when network response is received and the document started loading. referer : Union[str, NoneType] Referer header value. If provided it will take preference over the referer header value set by `page.set_extra_http_headers()`. @@ -7147,12 +7153,12 @@ def reload( self, *, timeout: float = None, - wait_until: Literal["domcontentloaded", "load", "networkidle"] = None + wait_until: Literal["commit", "domcontentloaded", "load", "networkidle"] = None ) -> typing.Optional["Response"]: """Page.reload - Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of the - last redirect. + This method reloads the current page, in the same way as if the user had triggered a browser refresh. Returns the main + resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect. Parameters ---------- @@ -7161,11 +7167,12 @@ def reload( changed by using the `browser_context.set_default_navigation_timeout()`, `browser_context.set_default_timeout()`, `page.set_default_navigation_timeout()` or `page.set_default_timeout()` methods. - wait_until : Union["domcontentloaded", "load", "networkidle", NoneType] + wait_until : Union["commit", "domcontentloaded", "load", "networkidle", NoneType] When to consider operation succeeded, defaults to `load`. Events can be either: - `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired. - `'load'` - consider operation to be finished when the `load` event is fired. - `'networkidle'` - consider operation to be finished when there are no network connections for at least `500` ms. + - `'commit'` - consider operation to be finished when network response is received and the document started loading. Returns ------- @@ -7234,7 +7241,7 @@ def wait_for_url( self, url: typing.Union[str, typing.Pattern, typing.Callable[[str], bool]], *, - wait_until: Literal["domcontentloaded", "load", "networkidle"] = None, + wait_until: Literal["commit", "domcontentloaded", "load", "networkidle"] = None, timeout: float = None ) -> NoneType: """Page.wait_for_url @@ -7254,11 +7261,12 @@ def wait_for_url( A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation. Note that if the parameter is a string without wilcard characters, the method will wait for navigation to URL that is exactly equal to the string. - wait_until : Union["domcontentloaded", "load", "networkidle", NoneType] + wait_until : Union["commit", "domcontentloaded", "load", "networkidle", NoneType] When to consider operation succeeded, defaults to `load`. Events can be either: - `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired. - `'load'` - consider operation to be finished when the `load` event is fired. - `'networkidle'` - consider operation to be finished when there are no network connections for at least `500` ms. + - `'commit'` - consider operation to be finished when network response is received and the document started loading. timeout : Union[float, NoneType] Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the `browser_context.set_default_navigation_timeout()`, @@ -7316,7 +7324,7 @@ def go_back( self, *, timeout: float = None, - wait_until: Literal["domcontentloaded", "load", "networkidle"] = None + wait_until: Literal["commit", "domcontentloaded", "load", "networkidle"] = None ) -> typing.Optional["Response"]: """Page.go_back @@ -7332,11 +7340,12 @@ def go_back( changed by using the `browser_context.set_default_navigation_timeout()`, `browser_context.set_default_timeout()`, `page.set_default_navigation_timeout()` or `page.set_default_timeout()` methods. - wait_until : Union["domcontentloaded", "load", "networkidle", NoneType] + wait_until : Union["commit", "domcontentloaded", "load", "networkidle", NoneType] When to consider operation succeeded, defaults to `load`. Events can be either: - `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired. - `'load'` - consider operation to be finished when the `load` event is fired. - `'networkidle'` - consider operation to be finished when there are no network connections for at least `500` ms. + - `'commit'` - consider operation to be finished when network response is received and the document started loading. Returns ------- @@ -7354,7 +7363,7 @@ def go_forward( self, *, timeout: float = None, - wait_until: Literal["domcontentloaded", "load", "networkidle"] = None + wait_until: Literal["commit", "domcontentloaded", "load", "networkidle"] = None ) -> typing.Optional["Response"]: """Page.go_forward @@ -7370,11 +7379,12 @@ def go_forward( changed by using the `browser_context.set_default_navigation_timeout()`, `browser_context.set_default_timeout()`, `page.set_default_navigation_timeout()` or `page.set_default_timeout()` methods. - wait_until : Union["domcontentloaded", "load", "networkidle", NoneType] + wait_until : Union["commit", "domcontentloaded", "load", "networkidle", NoneType] When to consider operation succeeded, defaults to `load`. Events can be either: - `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired. - `'load'` - consider operation to be finished when the `load` event is fired. - `'networkidle'` - consider operation to be finished when there are no network connections for at least `500` ms. + - `'commit'` - consider operation to be finished when network response is received and the document started loading. Returns ------- @@ -9187,7 +9197,7 @@ def expect_navigation( self, *, url: typing.Union[str, typing.Pattern, typing.Callable[[str], bool]] = None, - wait_until: Literal["domcontentloaded", "load", "networkidle"] = None, + wait_until: Literal["commit", "domcontentloaded", "load", "networkidle"] = None, timeout: float = None ) -> EventContextManager["Response"]: """Page.expect_navigation @@ -9217,11 +9227,12 @@ def expect_navigation( A glob pattern, regex pattern or predicate receiving [URL] to match while waiting for the navigation. Note that if the parameter is a string without wilcard characters, the method will wait for navigation to URL that is exactly equal to the string. - wait_until : Union["domcontentloaded", "load", "networkidle", NoneType] + wait_until : Union["commit", "domcontentloaded", "load", "networkidle", NoneType] When to consider operation succeeded, defaults to `load`. Events can be either: - `'domcontentloaded'` - consider operation to be finished when the `DOMContentLoaded` event is fired. - `'load'` - consider operation to be finished when the `load` event is fired. - `'networkidle'` - consider operation to be finished when there are no network connections for at least `500` ms. + - `'commit'` - consider operation to be finished when network response is received and the document started loading. timeout : Union[float, NoneType] Maximum operation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the `browser_context.set_default_navigation_timeout()`, diff --git a/setup.py b/setup.py index cff671fc7..bdbff87be 100644 --- a/setup.py +++ b/setup.py @@ -28,7 +28,7 @@ InWheel = None from wheel.bdist_wheel import bdist_wheel as BDistWheelCommand -driver_version = "1.16.0-next-1634703014000" +driver_version = "1.17.0-next-1635811939000" def extractall(zip: zipfile.ZipFile, path: str) -> None: @@ -88,9 +88,7 @@ def run(self) -> None: for platform in platforms: zip_file = f"playwright-{driver_version}-{platform['zip_name']}.zip" if not os.path.exists("driver/" + zip_file): - url = "https://playwright.azureedge.net/builds/driver/" - url += "next/" - url += zip_file + url = f"https://playwright.azureedge.net/builds/driver/next/{zip_file}" print(f"Fetching {url}") # Don't replace this with urllib - Python won't have certificates to do SSL on all platforms. subprocess.check_call(["curl", url, "-o", "driver/" + zip_file]) diff --git a/tests/async/test_navigation.py b/tests/async/test_navigation.py index e00ba26dc..9ec0a7d0a 100644 --- a/tests/async/test_navigation.py +++ b/tests/async/test_navigation.py @@ -225,7 +225,7 @@ async def test_goto_should_throw_if_networkidle2_is_passed_as_an_option(page, se with pytest.raises(Error) as exc_info: await page.goto(server.EMPTY_PAGE, wait_until="networkidle2") assert ( - "wait_until: expected one of (load|domcontentloaded|networkidle)" + "wait_until: expected one of (load|domcontentloaded|networkidle|commit)" in exc_info.value.message ) @@ -421,6 +421,11 @@ async def test_goto_should_reject_referer_option_when_set_extra_http_headers_pro assert server.PREFIX + "/grid.html" in exc_info.value.message +async def test_goto_should_work_with_commit(page: Page, server): + await page.goto(server.EMPTY_PAGE, wait_until="commit") + assert page.url == server.EMPTY_PAGE + + async def test_network_idle_should_navigate_to_empty_page_with_networkidle( page, server ): @@ -632,6 +637,17 @@ async def test_expect_navigation_should_work_for_cross_process_navigations( await goto_task +async def test_wait_for_nav_should_work_with_commit(page: Page, server): + await page.goto(server.EMPTY_PAGE) + async with page.expect_navigation(wait_until="commit") as response_info: + await page.evaluate( + "url => window.location.href = url", server.PREFIX + "/grid.html" + ) + response = await response_info.value + assert response.ok + assert "grid.html" in response.url + + async def test_wait_for_load_state_should_respect_timeout(page, server): requests = [] @@ -656,7 +672,7 @@ async def test_wait_for_load_state_should_throw_for_bad_state(page, server): with pytest.raises(Error) as exc_info: await page.wait_for_load_state("bad") assert ( - "state: expected one of (load|domcontentloaded|networkidle)" + "state: expected one of (load|domcontentloaded|networkidle|commit)" in exc_info.value.message ) diff --git a/tests/async/test_wait_for_url.py b/tests/async/test_wait_for_url.py index 4c4882170..40d400035 100644 --- a/tests/async/test_wait_for_url.py +++ b/tests/async/test_wait_for_url.py @@ -120,3 +120,12 @@ async def test_wait_for_url_should_work_with_url_match_for_same_document_navigat await page.evaluate("history.pushState({}, '', '/third.html')") await page.wait_for_url(re.compile(r"third\.html")) assert "/third.html" in page.url + + +async def test_wait_for_url_should_work_with_commit(page: Page, server): + await page.goto(server.EMPTY_PAGE) + await page.evaluate( + "url => window.location.href = url", server.PREFIX + "/grid.html" + ) + await page.wait_for_url("**/grid.html", wait_until="commit") + assert "grid.html" in page.url diff --git a/tests/async/test_worker.py b/tests/async/test_worker.py index 3ec764efa..b9adf916d 100644 --- a/tests/async/test_worker.py +++ b/tests/async/test_worker.py @@ -51,7 +51,9 @@ async def test_workers_should_emit_created_and_destroyed_events(page: Page): assert await worker_destroyed_promise == worker with pytest.raises(Error) as exc: await worker_this_obj.get_property("self") - assert "Target closed" in exc.value.message + assert ( + "Worker was closed" in exc.value.message or "Target closed" in exc.value.message + ) async def test_workers_should_report_console_logs(page):