Skip to content

feat(roll): roll Playwright 1.17.0-next-1635811939000 #1003

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Playwright is a Python library to automate [Chromium](https://www.chromium.org/H

| | Linux | macOS | Windows |
| :--- | :---: | :---: | :---: |
| Chromium <!-- GEN:chromium-version -->97.0.4666.0<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| Chromium <!-- GEN:chromium-version -->97.0.4681.0<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| WebKit <!-- GEN:webkit-version -->15.4<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| Firefox <!-- GEN:firefox-version -->93.0<!-- GEN:stop --> | ✅ | ✅ | ✅ |

Expand Down
3 changes: 1 addition & 2 deletions playwright/_impl/_artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
)
Expand Down
5 changes: 2 additions & 3 deletions playwright/_impl/_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions playwright/_impl/_browser_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
)
Expand Down
5 changes: 2 additions & 3 deletions playwright/_impl/_browser_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions playwright/_impl/_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 13 additions & 4 deletions playwright/_impl/_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -199,20 +199,29 @@ 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
):
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)
Expand Down
2 changes: 1 addition & 1 deletion playwright/_impl/_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
6 changes: 3 additions & 3 deletions playwright/_impl/_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
Expand Down Expand Up @@ -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()))

Expand Down
18 changes: 8 additions & 10 deletions playwright/_impl/_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
7 changes: 1 addition & 6 deletions playwright/_impl/_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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."
)
Expand Down
Loading