diff --git a/README.md b/README.md index 2731c3a28..93a5011bb 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 108.0.5359.22 | ✅ | ✅ | ✅ | +| Chromium 108.0.5359.29 | ✅ | ✅ | ✅ | | WebKit 16.0 | ✅ | ✅ | ✅ | | Firefox 106.0 | ✅ | ✅ | ✅ | diff --git a/playwright/_impl/_browser_context.py b/playwright/_impl/_browser_context.py index 2afbab914..07c9ae79e 100644 --- a/playwright/_impl/_browser_context.py +++ b/playwright/_impl/_browser_context.py @@ -163,6 +163,14 @@ def __init__( self.once( self.Events.Close, lambda context: self._closed_future.set_result(True) ) + self._set_event_to_subscription_mapping( + { + BrowserContext.Events.Request: "request", + BrowserContext.Events.Response: "response", + BrowserContext.Events.RequestFinished: "requestFinished", + BrowserContext.Events.RequestFailed: "requestFailed", + } + ) def __repr__(self) -> str: return f"" diff --git a/playwright/_impl/_connection.py b/playwright/_impl/_connection.py index fd15bc6e4..08652e3e4 100644 --- a/playwright/_impl/_connection.py +++ b/playwright/_impl/_connection.py @@ -119,6 +119,8 @@ def __init__( if self._parent: self._parent._objects[guid] = self + self._event_to_subscription_mapping: Dict[str, str] = {} + def _dispose(self) -> None: # Clean up from parent and connection. if self._parent: @@ -135,6 +137,26 @@ def _adopt(self, child: "ChannelOwner") -> None: self._objects[child._guid] = child child._parent = self + def _set_event_to_subscription_mapping(self, mapping: Dict[str, str]) -> None: + self._event_to_subscription_mapping = mapping + + def _update_subscription(self, event: str, enabled: bool) -> None: + protocol_event = self._event_to_subscription_mapping.get(event) + if protocol_event: + self._channel.send_no_reply( + "updateSubscription", {"event": protocol_event, "enabled": enabled} + ) + + def _add_event_handler(self, event: str, k: Any, v: Any) -> None: + if not self.listeners(event): + self._update_subscription(event, True) + super()._add_event_handler(event, k, v) + + def remove_listener(self, event: str, f: Any) -> None: + super().remove_listener(event, f) + if not self.listeners(event): + self._update_subscription(event, False) + class ProtocolCallback: def __init__(self, loop: asyncio.AbstractEventLoop) -> None: diff --git a/playwright/_impl/_element_handle.py b/playwright/_impl/_element_handle.py index 7e20dac1d..0cf33a160 100644 --- a/playwright/_impl/_element_handle.py +++ b/playwright/_impl/_element_handle.py @@ -218,14 +218,6 @@ async def type( ) -> None: await self._channel.send("type", locals_to_params(locals())) - async def clear( - self, - timeout: float = None, - noWaitAfter: bool = None, - force: bool = None, - ) -> None: - await self.fill("", **locals_to_params(locals())) - async def press( self, key: str, diff --git a/playwright/_impl/_frame.py b/playwright/_impl/_frame.py index 0f446b6f3..2ccb8da6c 100644 --- a/playwright/_impl/_frame.py +++ b/playwright/_impl/_frame.py @@ -794,22 +794,5 @@ async def set_checked( trial=trial, ) - async def clear( - self, - selector: str, - timeout: float = None, - noWaitAfter: bool = None, - force: bool = None, - strict: bool = None, - ) -> None: - await self.fill( - selector, - "", - timeout=timeout, - noWaitAfter=noWaitAfter, - force=force, - strict=strict, - ) - async def _highlight(self, selector: str) -> None: await self._channel.send("highlight", {"selector": selector}) diff --git a/playwright/_impl/_page.py b/playwright/_impl/_page.py index 2e4c27c7e..31b058f64 100644 --- a/playwright/_impl/_page.py +++ b/playwright/_impl/_page.py @@ -221,6 +221,16 @@ def __init__( else None, ) + self._set_event_to_subscription_mapping( + { + Page.Events.Request: "request", + Page.Events.Response: "response", + Page.Events.RequestFinished: "requestFinished", + Page.Events.RequestFailed: "requestFailed", + Page.Events.FileChooser: "fileChooser", + } + ) + def __repr__(self) -> str: return f"" @@ -294,20 +304,6 @@ def _on_video(self, params: Any) -> None: artifact = from_channel(params["artifact"]) cast(Video, self.video)._artifact_ready(artifact) - def _add_event_handler(self, event: str, k: Any, v: Any) -> None: - if event == Page.Events.FileChooser and len(self.listeners(event)) == 0: - self._channel.send_no_reply( - "setFileChooserInterceptedNoReply", {"intercepted": True} - ) - super()._add_event_handler(event, k, v) - - def remove_listener(self, event: str, f: Any) -> None: - super().remove_listener(event, f) - if event == Page.Events.FileChooser and len(self.listeners(event)) == 0: - self._channel.send_no_reply( - "setFileChooserInterceptedNoReply", {"intercepted": False} - ) - @property def context(self) -> "BrowserContext": return self._browser_context @@ -545,12 +541,14 @@ async def go_forward( async def emulate_media( self, - media: Literal["print", "screen"] = None, + media: Literal["null", "print", "screen"] = None, colorScheme: ColorScheme = None, reducedMotion: ReducedMotion = None, forcedColors: ForcedColors = None, ) -> None: params = locals_to_params(locals()) + if "media" in params: + params["media"] = "no-override" if params["media"] == "null" else media if "colorScheme" in params: params["colorScheme"] = ( "no-override" if params["colorScheme"] == "null" else colorScheme @@ -741,23 +739,6 @@ async def fill( ) -> None: return await self._main_frame.fill(**locals_to_params(locals())) - async def clear( - self, - selector: str, - timeout: float = None, - noWaitAfter: bool = None, - force: bool = None, - strict: bool = None, - ) -> None: - await self.fill( - selector, - "", - timeout=timeout, - noWaitAfter=noWaitAfter, - force=force, - strict=strict, - ) - def locator( self, selector: str, diff --git a/playwright/async_api/_generated.py b/playwright/async_api/_generated.py index 842544448..99667d85d 100644 --- a/playwright/async_api/_generated.py +++ b/playwright/async_api/_generated.py @@ -2228,42 +2228,6 @@ async def type( ) ) - async def clear( - self, - *, - timeout: typing.Optional[float] = None, - no_wait_after: typing.Optional[bool] = None, - force: typing.Optional[bool] = None - ) -> None: - """ElementHandle.clear - - This method waits for [actionability](https://playwright.dev/python/docs/actionability) checks, focuses the element, clears it and triggers an - `input` event after clearing. - - If the target element is not an ``, `