Skip to content

Commit 8a32713

Browse files
committed
chore: roll 1.58
1 parent d3f5438 commit 8a32713

File tree

11 files changed

+602
-85
lines changed

11 files changed

+602
-85
lines changed

README.md

Lines changed: 2 additions & 2 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 -->143.0.7499.4<!-- GEN:stop --> ||||
7+
| Chromium <!-- GEN:chromium-version -->144.0.7559.20<!-- GEN:stop --> ||||
88
| WebKit <!-- GEN:webkit-version -->26.0<!-- GEN:stop --> ||||
9-
| Firefox <!-- GEN:firefox-version -->144.0.2<!-- GEN:stop --> ||||
9+
| Firefox <!-- GEN:firefox-version -->146.0.1<!-- GEN:stop --> ||||
1010

1111
## Documentation
1212

playwright/_impl/_browser_type.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ async def connect_over_cdp(
200200
timeout: float = None,
201201
slowMo: float = None,
202202
headers: Dict[str, str] = None,
203+
isLocal: bool = None,
203204
) -> Browser:
204205
params = locals_to_params(locals())
205206
if params.get("headers"):

playwright/_impl/_console_message.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def type(self) -> Union[
5757
Literal["startGroup"],
5858
Literal["startGroupCollapsed"],
5959
Literal["table"],
60+
Literal["time"],
6061
Literal["timeEnd"],
6162
Literal["trace"],
6263
Literal["warning"],

playwright/_impl/_object_factory.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
WebSocketRoute,
3535
)
3636
from playwright._impl._page import BindingCall, Page, Worker
37+
from playwright._impl._page_agent import PageAgent
3738
from playwright._impl._playwright import Playwright
3839
from playwright._impl._stream import Stream
3940
from playwright._impl._tracing import Tracing
@@ -79,6 +80,8 @@ def create_remote_object(
7980
return local_utils
8081
if type == "Page":
8182
return Page(parent, type, guid, initializer)
83+
if type == "PageAgent":
84+
return PageAgent(parent, type, guid, initializer)
8285
if type == "Playwright":
8386
return Playwright(parent, type, guid, initializer)
8487
if type == "Request":

playwright/_impl/_page.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
from playwright._impl._fetch import APIRequestContext
107107
from playwright._impl._locator import FrameLocator, Locator
108108
from playwright._impl._network import WebSocket
109+
from playwright._impl._page_agent import PageAgent
109110

110111

111112
class LocatorHandler:
@@ -1117,6 +1118,45 @@ def workers(self) -> List["Worker"]:
11171118
def request(self) -> "APIRequestContext":
11181119
return self.context.request
11191120

1121+
async def agent(
1122+
self,
1123+
provider: Dict[str, Any] = None,
1124+
cache: Dict[str, str] = None,
1125+
maxTokens: int = None,
1126+
maxTurns: int = None,
1127+
secrets: Dict[str, str] = None,
1128+
systemPrompt: str = None,
1129+
) -> "PageAgent":
1130+
from playwright._impl._page_agent import PageAgent
1131+
1132+
params: Dict[str, Any] = {}
1133+
if provider is not None:
1134+
if "api" in provider:
1135+
params["api"] = provider["api"]
1136+
if "apiEndpoint" in provider:
1137+
params["apiEndpoint"] = provider["apiEndpoint"]
1138+
if "apiKey" in provider:
1139+
params["apiKey"] = provider["apiKey"]
1140+
if "model" in provider:
1141+
params["model"] = provider["model"]
1142+
if cache is not None:
1143+
if "cacheFile" in cache:
1144+
params["cacheFile"] = cache["cacheFile"]
1145+
if "cacheOutFile" in cache:
1146+
params["cacheOutFile"] = cache["cacheOutFile"]
1147+
if maxTokens is not None:
1148+
params["maxTokens"] = maxTokens
1149+
if maxTurns is not None:
1150+
params["maxTurns"] = maxTurns
1151+
if secrets is not None:
1152+
params["secrets"] = [
1153+
{"name": name, "value": value} for name, value in secrets.items()
1154+
]
1155+
if systemPrompt is not None:
1156+
params["systemPrompt"] = systemPrompt
1157+
result = await self._channel.send_return_as_dict("agent", None, params)
1158+
return from_channel(result["agent"])
1159+
11201160
async def pause(self) -> None:
11211161
default_navigation_timeout = (
11221162
self._browser_context._timeout_settings.default_navigation_timeout()

playwright/_impl/_page_agent.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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 types import SimpleNamespace
16+
from typing import TYPE_CHECKING, Any, Dict, List, Optional
17+
18+
from playwright._impl._connection import ChannelOwner, from_channel
19+
from playwright._impl._helper import locals_to_params
20+
21+
22+
class PageAgent(ChannelOwner):
23+
Events = SimpleNamespace(
24+
Turn="turn",
25+
)
26+
27+
def __init__(
28+
self, parent: ChannelOwner, type: str, guid: str, initializer: Dict
29+
) -> None:
30+
super().__init__(parent, type, guid, initializer)
31+
self._channel.on(
32+
"turn", lambda params: self.emit(PageAgent.Events.Turn, params)
33+
)
34+
35+
async def expect(
36+
self,
37+
expectation: str,
38+
cacheKey: str = None,
39+
maxTokens: int = None,
40+
maxTurns: int = None,
41+
timeout: float = None,
42+
) -> None:
43+
await self._channel.send("expect", None, locals_to_params(locals()))
44+
45+
async def perform(
46+
self,
47+
task: str,
48+
cacheKey: str = None,
49+
maxTokens: int = None,
50+
maxTurns: int = None,
51+
timeout: float = None,
52+
) -> Dict[str, Any]:
53+
return await self._channel.send_return_as_dict(
54+
"perform", None, locals_to_params(locals())
55+
)
56+
57+
async def extract(
58+
self,
59+
query: str,
60+
schema: Dict[str, Any],
61+
cacheKey: str = None,
62+
maxTokens: int = None,
63+
maxTurns: int = None,
64+
timeout: float = None,
65+
) -> Dict[str, Any]:
66+
# TODO: implement pydantic
67+
return await self._channel.send_return_as_dict(
68+
"extract", None, locals_to_params(locals())
69+
)
70+
71+
async def dispose(self) -> None:
72+
await self._channel.send("dispose", None)

0 commit comments

Comments
 (0)