Skip to content

Commit e971bb9

Browse files
committed
chore: roll to 1.59.1
1 parent 3aecfcf commit e971bb9

22 files changed

Lines changed: 2029 additions & 166 deletions

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ Playwright is a Python library to automate [Chromium](https://www.chromium.org/H
44

55
| | Linux | macOS | Windows |
66
| :--- | :---: | :---: | :---: |
7-
| Chromium <!-- GEN:chromium-version -->145.0.7632.6<!-- GEN:stop --> ||||
8-
| WebKit <!-- GEN:webkit-version -->26.0<!-- GEN:stop --> ||||
9-
| Firefox <!-- GEN:firefox-version -->146.0.1<!-- GEN:stop --> ||||
7+
| Chromium <!-- GEN:chromium-version -->147.0.7727.15<!-- GEN:stop --> ||||
8+
| WebKit <!-- GEN:webkit-version -->26.4<!-- GEN:stop --> ||||
9+
| Firefox <!-- GEN:firefox-version -->148.0.2<!-- GEN:stop --> ||||
1010

1111
## Documentation
1212

playwright/_impl/_api_structures.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ class FrameExpectOptions(TypedDict, total=False):
214214
timeout: Optional[float]
215215

216216

217-
class FrameExpectResult(TypedDict):
217+
class FrameExpectResult(TypedDict, total=False):
218218
matches: bool
219219
received: Any
220220
log: List[str]
@@ -307,7 +307,26 @@ class FrameExpectResult(TypedDict):
307307
]
308308

309309

310-
class TracingGroupLocation(TypedDict):
310+
class TracingGroupLocation(TypedDict, total=False):
311311
file: str
312312
line: Optional[int]
313313
column: Optional[int]
314+
315+
316+
class BindResult(TypedDict):
317+
endpoint: str
318+
319+
320+
class PausedDetailsLocation(TypedDict, total=False):
321+
file: str
322+
line: Optional[int]
323+
column: Optional[int]
324+
325+
326+
class PausedDetails(TypedDict):
327+
location: PausedDetailsLocation
328+
title: str
329+
330+
331+
class OnFrame(TypedDict):
332+
data: bytes

playwright/_impl/_browser.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
)
2828

2929
from playwright._impl._api_structures import (
30+
BindResult,
3031
ClientCertificate,
3132
Geolocation,
3233
HttpCredentials,
@@ -240,6 +241,19 @@ async def close(self, reason: str = None) -> None:
240241
if not is_target_closed_error(e):
241242
raise e
242243

244+
async def bind(
245+
self,
246+
title: str,
247+
workspaceDir: str = None,
248+
host: str = None,
249+
port: int = None,
250+
) -> BindResult:
251+
params = locals_to_params(locals())
252+
return await self._channel.send("startServer", None, params)
253+
254+
async def unbind(self) -> None:
255+
await self._channel.send("stopServer", None)
256+
243257
@property
244258
def version(self) -> str:
245259
return self._initializer["version"]

playwright/_impl/_browser_context.py

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@
4646
from_nullable_channel,
4747
)
4848
from playwright._impl._console_message import ConsoleMessage
49+
from playwright._impl._debugger import Debugger
4950
from playwright._impl._dialog import Dialog
51+
from playwright._impl._disposable import Disposable, DisposableStub
5052
from playwright._impl._errors import Error, TargetClosedError
5153
from playwright._impl._event_context_manager import EventContextManagerImpl
5254
from playwright._impl._fetch import APIRequestContext
@@ -122,6 +124,7 @@ def __init__(
122124
self._base_url: Optional[str] = self._options.get("baseURL")
123125
self._videos_dir: Optional[str] = self._options.get("recordVideo")
124126
self._tracing = cast(Tracing, from_channel(initializer["tracing"]))
127+
self._debugger: Debugger = from_channel(initializer["debugger"])
125128
self._har_recorders: Dict[str, HarRecordingMetadata] = {}
126129
self._request: APIRequestContext = from_channel(initializer["requestContext"])
127130
self._request._timeout_settings = self._timeout_settings
@@ -392,16 +395,18 @@ async def set_offline(self, offline: bool) -> None:
392395

393396
async def add_init_script(
394397
self, script: str = None, path: Union[str, Path] = None
395-
) -> None:
398+
) -> Disposable:
396399
if path:
397400
script = (await async_readfile(path)).decode()
398401
if not isinstance(script, str):
399402
raise Error("Either path or script parameter must be specified")
400-
await self._channel.send("addInitScript", None, dict(source=script))
403+
return from_channel(
404+
await self._channel.send("addInitScript", None, dict(source=script))
405+
)
401406

402407
async def expose_binding(
403408
self, name: str, callback: Callable, handle: bool = None
404-
) -> None:
409+
) -> Disposable:
405410
for page in self._pages:
406411
if name in page._bindings:
407412
raise Error(
@@ -410,16 +415,18 @@ async def expose_binding(
410415
if name in self._bindings:
411416
raise Error(f'Function "{name}" has been already registered')
412417
self._bindings[name] = callback
413-
await self._channel.send(
414-
"exposeBinding", None, dict(name=name, needsHandle=handle or False)
418+
return from_channel(
419+
await self._channel.send(
420+
"exposeBinding", None, dict(name=name, needsHandle=handle or False)
421+
)
415422
)
416423

417-
async def expose_function(self, name: str, callback: Callable) -> None:
418-
await self.expose_binding(name, lambda source, *args: callback(*args))
424+
async def expose_function(self, name: str, callback: Callable) -> Disposable:
425+
return await self.expose_binding(name, lambda source, *args: callback(*args))
419426

420427
async def route(
421428
self, url: URLMatch, handler: RouteHandlerCallback, times: int = None
422-
) -> None:
429+
) -> DisposableStub:
423430
self._routes.insert(
424431
0,
425432
RouteHandler(
@@ -431,6 +438,7 @@ async def route(
431438
),
432439
)
433440
await self._update_interception_patterns()
441+
return DisposableStub(lambda: self.unroute(url, handler))
434442

435443
async def unroute(
436444
self, url: URLMatch, handler: Optional[RouteHandlerCallback] = None
@@ -564,6 +572,9 @@ def expect_event(
564572
waiter.wait_for_event(self, event, predicate)
565573
return EventContextManagerImpl(waiter.result())
566574

575+
def is_closed(self) -> bool:
576+
return self._closing_or_closed
577+
567578
def _on_close(self) -> None:
568579
self._closing_or_closed = True
569580
if self._browser:
@@ -627,6 +638,16 @@ async def storage_state(
627638
await async_writefile(path, json.dumps(result))
628639
return result
629640

641+
async def set_storage_state(
642+
self, storageState: Union[StorageState, str, Path]
643+
) -> None:
644+
state: StorageState
645+
if isinstance(storageState, (str, Path)):
646+
state = json.loads(await async_readfile(storageState))
647+
elif storageState:
648+
state = storageState
649+
await self._channel.send("setStorageState", None, {"storageState": state})
650+
630651
def _effective_close_reason(self) -> Optional[str]:
631652
if self._close_reason:
632653
return self._close_reason
@@ -753,6 +774,10 @@ async def new_cdp_session(self, page: Union[Page, Frame]) -> CDPSession:
753774
def tracing(self) -> Tracing:
754775
return self._tracing
755776

777+
@property
778+
def debugger(self) -> Debugger:
779+
return self._debugger
780+
756781
@property
757782
def request(self) -> "APIRequestContext":
758783
return self._request

playwright/_impl/_browser_type.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ async def launch(
8888
tracesDir: Union[pathlib.Path, str] = None,
8989
chromiumSandbox: bool = None,
9090
firefoxUserPrefs: Dict[str, Union[str, float, bool]] = None,
91+
artifactsDir: Union[Path, str] = None,
9192
) -> Browser:
9293
params = locals_to_params(locals())
9394
normalize_launch_params(params)
@@ -156,6 +157,7 @@ async def launch_persistent_context(
156157
recordHarMode: HarMode = None,
157158
recordHarContent: HarContentPolicy = None,
158159
clientCertificates: List[ClientCertificate] = None,
160+
artifactsDir: Union[Path, str] = None,
159161
) -> BrowserContext:
160162
userDataDir = self._user_data_dir(userDataDir)
161163
params = locals_to_params(locals())
@@ -213,7 +215,7 @@ async def connect_over_cdp(
213215

214216
async def connect(
215217
self,
216-
wsEndpoint: str,
218+
endpoint: str,
217219
timeout: float = None,
218220
slowMo: float = None,
219221
headers: Dict[str, str] = None,
@@ -229,7 +231,7 @@ async def connect(
229231
"connect",
230232
None,
231233
{
232-
"wsEndpoint": wsEndpoint,
234+
"endpoint": endpoint,
233235
"headers": headers,
234236
"slowMo": slowMo,
235237
"timeout": timeout if timeout is not None else 0,

playwright/_impl/_cdp_session.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def __init__(
2424
) -> None:
2525
super().__init__(parent, type, guid, initializer)
2626
self._channel.on("event", lambda params: self._on_event(params))
27+
self._channel.on("close", lambda _: self.emit("close"))
2728

2829
def _on_event(self, params: Any) -> None:
2930
self.emit(params["method"], params.get("params"))

playwright/_impl/_console_message.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ def args(self) -> List[JSHandle]:
7676
def location(self) -> SourceLocation:
7777
return self._event["location"]
7878

79+
@property
80+
def timestamp(self) -> float:
81+
return self._event["timestamp"]
82+
7983
@property
8084
def page(self) -> Optional["Page"]:
8185
return self._page

playwright/_impl/_debugger.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Copyright (c) Microsoft Corporation.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from typing import Dict, Optional
16+
17+
from playwright._impl._api_structures import PausedDetails, PausedDetailsLocation
18+
from playwright._impl._connection import ChannelOwner
19+
20+
21+
class Debugger(ChannelOwner):
22+
Events = {"PausedStateChanged": "pausedStateChanged"}
23+
24+
def __init__(
25+
self, parent: ChannelOwner, type: str, guid: str, initializer: Dict
26+
) -> None:
27+
super().__init__(parent, type, guid, initializer)
28+
self._paused_details: Optional[PausedDetails] = None
29+
self._channel.on(
30+
"pausedStateChanged",
31+
lambda params: self._on_paused_state_changed(params.get("pausedDetails")),
32+
)
33+
34+
def _on_paused_state_changed(self, paused_details: Optional[PausedDetails]) -> None:
35+
self._paused_details = paused_details
36+
self.emit(Debugger.Events["PausedStateChanged"])
37+
38+
async def request_pause(self) -> None:
39+
await self._channel.send("requestPause", None)
40+
41+
async def resume(self) -> None:
42+
await self._channel.send("resume", None)
43+
44+
async def next(self) -> None:
45+
await self._channel.send("next", None)
46+
47+
async def run_to(self, location: PausedDetailsLocation) -> None:
48+
await self._channel.send("runTo", None, {"location": location})
49+
50+
@property
51+
def paused_details(self) -> Optional[PausedDetails]:
52+
return self._paused_details

playwright/_impl/_dialog.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from typing import TYPE_CHECKING, Dict, Optional
1616

1717
from playwright._impl._connection import ChannelOwner, from_nullable_channel
18+
from playwright._impl._errors import is_target_closed_error
1819
from playwright._impl._helper import locals_to_params
1920

2021
if TYPE_CHECKING: # pragma: no cover
@@ -51,7 +52,12 @@ async def accept(self, promptText: str = None) -> None:
5152
await self._channel.send("accept", None, locals_to_params(locals()))
5253

5354
async def dismiss(self) -> None:
54-
await self._channel.send(
55-
"dismiss",
56-
None,
57-
)
55+
try:
56+
await self._channel.send(
57+
"dismiss",
58+
None,
59+
)
60+
except Exception as e:
61+
if is_target_closed_error(e):
62+
return
63+
raise

playwright/_impl/_disposable.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Copyright (c) Microsoft Corporation.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from typing import Awaitable, Callable, Dict
16+
17+
from playwright._impl._connection import ChannelOwner
18+
from playwright._impl._errors import is_target_closed_error
19+
20+
21+
class Disposable(ChannelOwner):
22+
def __init__(
23+
self, parent: ChannelOwner, type: str, guid: str, initializer: Dict
24+
) -> None:
25+
super().__init__(parent, type, guid, initializer)
26+
27+
async def dispose(self) -> None:
28+
try:
29+
await self._channel.send(
30+
"dispose",
31+
None,
32+
)
33+
except Exception as e:
34+
if not is_target_closed_error(e):
35+
raise e
36+
37+
def __repr__(self) -> str:
38+
return "<Disposable>"
39+
40+
41+
class DisposableStub:
42+
def __init__(self, dispose_fn: Callable[[], Awaitable[None]]) -> None:
43+
self._dispose_fn = dispose_fn
44+
45+
async def dispose(self) -> None:
46+
await self._dispose_fn()
47+
48+
def __repr__(self) -> str:
49+
return "<Disposable>"

0 commit comments

Comments
 (0)