Skip to content

Commit c830b5f

Browse files
chore: roll Playwright to 1.66.0-next (049226728d) (#3365)
Co-authored-by: microsoft-playwright-automation[bot] <203992400+microsoft-playwright-automation[bot]@users.noreply.github.com>
1 parent de03c86 commit c830b5f

11 files changed

Lines changed: 152 additions & 21 deletions

File tree

‎DRIVER_VERSION‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
a018f24a4fc76e2120d3b35d2415f1e5bd4b073e
1+
049226728d2da8054db18b04782a9848b755855e

‎playwright/_impl/frame.py‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -386,18 +386,6 @@ async def evaluate(self, expression: str, arg: Serializable) -> Any:
386386
)
387387
return parse_result(result["value"])
388388

389-
async def _evaluate_expose_utility_script(
390-
self, expression: str, arg: Serializable
391-
) -> Any:
392-
result = await self._channel.evaluateExpression(
393-
expression=expression,
394-
# Python: undefined; see the docstring of js_handle.py.
395-
isFunction=None,
396-
arg=serialize_argument(arg),
397-
timeout=NO_TIMEOUT,
398-
)
399-
return parse_result(result["value"])
400-
401389
async def query_selector(
402390
self, selector: str, strict: Optional[bool]
403391
) -> Optional[ElementHandle]:

‎playwright/async_api/_generated.py‎

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4017,13 +4017,41 @@ async def connect_over_cdp(
40174017
A CDP websocket endpoint or http url to connect to. For example `http://localhost:9222/` or
40184018
`ws://127.0.0.1:9222/devtools/browser/387adf4c-243f-4051-a181-46798f4a46f4`.
40194019

4020-
Alternatively, a browser channel name such as `chrome` or `msedge` to connect to a browser with remote debugging
4021-
enabled in its default user data directory. On Linux, Playwright uses `CHROME_USER_DATA_DIR` when set. Otherwise,
4022-
it uses `CHROME_CONFIG_HOME`, then `XDG_CONFIG_HOME`, then `~/.config` to locate that directory.
4020+
Alternatively, a URL that tells which running browser to connect to:
4021+
- `remote-debugging://<channel>` - a browser with remote debugging enabled, for example
4022+
`remote-debugging://msedge`. The optional `userDataDir` parameter is the user data directory of the browser,
4023+
when it is not the default one: `remote-debugging://chrome?userDataDir=/path/to/data`. A bare channel name such
4024+
as `chrome` is the same as `remote-debugging://chrome`.
4025+
- `extension://<channel>/<profile directory>` - the tabs of a browser profile, through the
4026+
[Playwright Extension](https://chromewebstore.google.com/detail/playwright-extension/mmlmfjhmonkocbjadbfplnigmagldckm),
4027+
for example `extension://chrome/Profile 1`. Playwright opens the connect page of the extension in that profile,
4028+
and the user selects the tabs to share. Without the profile directory, Playwright uses the `Default` profile.
4029+
The optional parameters are `userDataDir`, the user data directory of the browser when it is not the default
4030+
one, and `executablePath`, the path to the browser executable when it is not at the standard location:
4031+
`extension://chromium?executablePath=/path/to/chrome&userDataDir=/path/to/data`. Pass the other options of this
4032+
connection in `headers`.
4033+
4034+
The values of `userDataDir` and `executablePath` must be URL-encoded, for example with `encodeURIComponent` or
4035+
`URLSearchParams`. The channel is a browser channel name such as `chrome`, `chrome-beta` or `msedge`. The default
4036+
user data directory of the channel is where the browser keeps its data. On Linux, Playwright uses
4037+
`CHROME_USER_DATA_DIR` when set. Otherwise, it uses `CHROME_CONFIG_HOME`, then `XDG_CONFIG_HOME`, then `~/.config`
4038+
to locate that directory.
40234039
artifacts_dir : Union[pathlib.Path, str, None]
40244040
If specified, browser artifacts (such as traces and downloads) are saved into this directory.
40254041
headers : Union[Dict[str, str], None]
40264042
Additional HTTP headers to be sent with connect request. Optional.
4043+
4044+
When `endpoint_url` is an extension URL such as `extension://chrome`, the headers are not sent. They are the
4045+
options of the connection:
4046+
- `x-playwright-extension-token` - the token of the extension. With the token, the user does not have to approve
4047+
the connection. Without the token, the user must approve the connection before `timeout` expires, so set it to
4048+
a value that gives the user enough time.
4049+
- `x-playwright-extension-client-name` - the name of the client that the extension shows to the user.
4050+
- `x-playwright-extension-tab-group` - pass `false` to keep the tabs out of a tab group.
4051+
- `x-playwright-extension-tab-group-title` - the title of the tab group.
4052+
- `x-playwright-extension-tab-group-color` - the color of the tab group: `green`, `blue`, `purple`, `orange`,
4053+
`pink`, `cyan`, `yellow` or `red`.
4054+
- `x-playwright-extension-background` - pass `true` to keep the tabs from becoming active.
40274055
is_local : Union[bool, None]
40284056
Tells Playwright that it runs on the same host as the CDP server. It will enable certain optimizations that rely
40294057
upon the file system being the same between Playwright and the Browser.

‎playwright/sync_api/_generated.py‎

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3943,13 +3943,41 @@ def connect_over_cdp(
39433943
A CDP websocket endpoint or http url to connect to. For example `http://localhost:9222/` or
39443944
`ws://127.0.0.1:9222/devtools/browser/387adf4c-243f-4051-a181-46798f4a46f4`.
39453945

3946-
Alternatively, a browser channel name such as `chrome` or `msedge` to connect to a browser with remote debugging
3947-
enabled in its default user data directory. On Linux, Playwright uses `CHROME_USER_DATA_DIR` when set. Otherwise,
3948-
it uses `CHROME_CONFIG_HOME`, then `XDG_CONFIG_HOME`, then `~/.config` to locate that directory.
3946+
Alternatively, a URL that tells which running browser to connect to:
3947+
- `remote-debugging://<channel>` - a browser with remote debugging enabled, for example
3948+
`remote-debugging://msedge`. The optional `userDataDir` parameter is the user data directory of the browser,
3949+
when it is not the default one: `remote-debugging://chrome?userDataDir=/path/to/data`. A bare channel name such
3950+
as `chrome` is the same as `remote-debugging://chrome`.
3951+
- `extension://<channel>/<profile directory>` - the tabs of a browser profile, through the
3952+
[Playwright Extension](https://chromewebstore.google.com/detail/playwright-extension/mmlmfjhmonkocbjadbfplnigmagldckm),
3953+
for example `extension://chrome/Profile 1`. Playwright opens the connect page of the extension in that profile,
3954+
and the user selects the tabs to share. Without the profile directory, Playwright uses the `Default` profile.
3955+
The optional parameters are `userDataDir`, the user data directory of the browser when it is not the default
3956+
one, and `executablePath`, the path to the browser executable when it is not at the standard location:
3957+
`extension://chromium?executablePath=/path/to/chrome&userDataDir=/path/to/data`. Pass the other options of this
3958+
connection in `headers`.
3959+
3960+
The values of `userDataDir` and `executablePath` must be URL-encoded, for example with `encodeURIComponent` or
3961+
`URLSearchParams`. The channel is a browser channel name such as `chrome`, `chrome-beta` or `msedge`. The default
3962+
user data directory of the channel is where the browser keeps its data. On Linux, Playwright uses
3963+
`CHROME_USER_DATA_DIR` when set. Otherwise, it uses `CHROME_CONFIG_HOME`, then `XDG_CONFIG_HOME`, then `~/.config`
3964+
to locate that directory.
39493965
artifacts_dir : Union[pathlib.Path, str, None]
39503966
If specified, browser artifacts (such as traces and downloads) are saved into this directory.
39513967
headers : Union[Dict[str, str], None]
39523968
Additional HTTP headers to be sent with connect request. Optional.
3969+
3970+
When `endpoint_url` is an extension URL such as `extension://chrome`, the headers are not sent. They are the
3971+
options of the connection:
3972+
- `x-playwright-extension-token` - the token of the extension. With the token, the user does not have to approve
3973+
the connection. Without the token, the user must approve the connection before `timeout` expires, so set it to
3974+
a value that gives the user enough time.
3975+
- `x-playwright-extension-client-name` - the name of the client that the extension shows to the user.
3976+
- `x-playwright-extension-tab-group` - pass `false` to keep the tabs out of a tab group.
3977+
- `x-playwright-extension-tab-group-title` - the title of the tab group.
3978+
- `x-playwright-extension-tab-group-color` - the color of the tab group: `green`, `blue`, `purple`, `orange`,
3979+
`pink`, `cyan`, `yellow` or `red`.
3980+
- `x-playwright-extension-background` - pass `true` to keep the tabs from becoming active.
39533981
is_local : Union[bool, None]
39543982
Tells Playwright that it runs on the same host as the CDP server. It will enable certain optimizations that rely
39553983
upon the file system being the same between Playwright and the Browser.

‎tests/async/library/chromium/test_connect_over_cdp.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import os
2020
import signal
2121
import sys
22+
import urllib.parse
2223
import urllib.request
2324
from contextlib import suppress
2425
from pathlib import Path
@@ -105,6 +106,13 @@ async def test_CD_001_should_connect_to_an_existing_cdp_session(
105106
assert len(contexts) == 1
106107
await cdp_browser.close()
107108

109+
url_browser = await browser_type.connect_over_cdp(
110+
"remote-debugging://chromium?"
111+
+ urllib.parse.urlencode({"userDataDir": str(user_data_dir)})
112+
)
113+
assert len(url_browser.contexts) == 1
114+
await url_browser.close()
115+
108116
if is_linux:
109117
environments: List[Dict[str, Optional[str]]] = [
110118
{

‎tests/async/library/test_browsertype_connect.py‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
from tests.helpers.remote_server import (
5353
KIND_LAUNCH_SERVER,
5454
KIND_RUN_SERVER,
55+
ChildProcess,
5556
RemoteServerStarter,
5657
RunServer,
5758
redirect_port_forwarding_for_test,
@@ -65,6 +66,21 @@
6566
KINDS = [KIND_LAUNCH_SERVER, KIND_RUN_SERVER]
6667

6768

69+
@pytest.fixture
70+
def child_process() -> Generator[Callable[..., ChildProcess], None, None]:
71+
"""Port of the childProcess fixture in tests/config/commonFixtures.ts."""
72+
processes: List[ChildProcess] = []
73+
74+
def start(command: List[str]) -> ChildProcess:
75+
process = ChildProcess(command)
76+
processes.append(process)
77+
return process
78+
79+
yield start
80+
for process in processes:
81+
process.kill()
82+
83+
6884
async def connect_browser(
6985
browser_type: BrowserType,
7086
launch_arguments: Dict,
@@ -1823,6 +1839,18 @@ async def test_BT_093_should_refuse_connecting_when_versions_do_not_match(
18231839
assert "client version: v" + client_version() in exc_info.value.message
18241840

18251841

1842+
async def test_BT_105_run_server_should_exit_when_stdin_closes(
1843+
child_process: Callable[..., ChildProcess],
1844+
) -> None:
1845+
node, cli = compute_driver_executable()
1846+
server = child_process([node, cli, "run-server", "--port=0"])
1847+
await asyncio.to_thread(server.wait_for_output, "Listening on ")
1848+
assert server.process.stdin
1849+
server.process.stdin.close()
1850+
# Python: a zero return code means exitCode: 0 and signal: null.
1851+
assert await asyncio.to_thread(server.exit_code) == 0
1852+
1853+
18261854
async def test_BT_094_should_filter_local_paths_from_unsafe_launch_options(
18271855
connect: Callable[..., Awaitable[Browser]],
18281856
start_remote_server: RemoteServerStarter,

‎tests/async/library/test_har.py‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,15 @@ async def test_HA_003_should_have_pages(page_with_har: PageWithHar) -> None:
149149
await har.page.goto("data:text/html,<title>Hello</title>")
150150
# For data: load comes before domcontentloaded...
151151
await har.page.wait_for_load_state("domcontentloaded")
152+
153+
page_with_dialog = await har.page.context.new_page()
154+
async with page_with_dialog.expect_event("dialog"):
155+
await page_with_dialog.goto(
156+
'data:text/html,<body onload="alert(1)">', wait_until="commit"
157+
)
158+
152159
log = await har.get_log()
153-
assert len(log["pages"]) == 1
160+
assert len(log["pages"]) == 2
154161
page_entry = log["pages"][0]
155162
assert page_entry["id"]
156163
assert page_entry["title"] == "Hello"

‎tests/sync/library/chromium/test_connect_over_cdp.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import signal
2020
import sys
2121
import time
22+
import urllib.parse
2223
import urllib.request
2324
from concurrent.futures import ThreadPoolExecutor
2425
from contextlib import suppress
@@ -117,6 +118,13 @@ def test_CD_001_should_connect_to_an_existing_cdp_session(
117118
assert len(contexts) == 1
118119
cdp_browser.close()
119120

121+
url_browser = browser_type.connect_over_cdp(
122+
"remote-debugging://chromium?"
123+
+ urllib.parse.urlencode({"userDataDir": str(user_data_dir)})
124+
)
125+
assert len(url_browser.contexts) == 1
126+
url_browser.close()
127+
120128
if is_linux:
121129
environments: List[Dict[str, Optional[str]]] = [
122130
{

‎tests/sync/library/test_browsertype_connect.py‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
from tests.helpers.remote_server import (
4646
KIND_LAUNCH_SERVER,
4747
KIND_RUN_SERVER,
48+
ChildProcess,
4849
RemoteServerStarter,
4950
RunServer,
5051
redirect_port_forwarding_for_test,
@@ -58,6 +59,21 @@
5859
KINDS = [KIND_LAUNCH_SERVER, KIND_RUN_SERVER]
5960

6061

62+
@pytest.fixture
63+
def child_process() -> Generator[Callable[..., ChildProcess], None, None]:
64+
"""Port of the childProcess fixture in tests/config/commonFixtures.ts."""
65+
processes: List[ChildProcess] = []
66+
67+
def start(command: List[str]) -> ChildProcess:
68+
process = ChildProcess(command)
69+
processes.append(process)
70+
return process
71+
72+
yield start
73+
for process in processes:
74+
process.kill()
75+
76+
6177
def connect_browser(
6278
browser_type: BrowserType,
6379
launch_arguments: Dict,
@@ -1848,6 +1864,18 @@ def test_BT_093_should_refuse_connecting_when_versions_do_not_match(
18481864
assert "client version: v" + client_version() in exc_info.value.message
18491865

18501866

1867+
def test_BT_105_run_server_should_exit_when_stdin_closes(
1868+
child_process: Callable[..., ChildProcess],
1869+
) -> None:
1870+
node, cli = compute_driver_executable()
1871+
server = child_process([node, cli, "run-server", "--port=0"])
1872+
server.wait_for_output("Listening on ")
1873+
assert server.process.stdin
1874+
server.process.stdin.close()
1875+
# Python: a zero return code means exitCode: 0 and signal: null.
1876+
assert server.exit_code() == 0
1877+
1878+
18511879
def test_BT_094_should_filter_local_paths_from_unsafe_launch_options(
18521880
connect: Callable[..., Browser],
18531881
start_remote_server: RemoteServerStarter,

‎tests/sync/library/test_har.py‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,15 @@ def test_HA_003_should_have_pages(page_with_har: PageWithHar) -> None:
148148
har.page.goto("data:text/html,<title>Hello</title>")
149149
# For data: load comes before domcontentloaded...
150150
har.page.wait_for_load_state("domcontentloaded")
151+
152+
page_with_dialog = har.page.context.new_page()
153+
with page_with_dialog.expect_event("dialog"):
154+
page_with_dialog.goto(
155+
'data:text/html,<body onload="alert(1)">', wait_until="commit"
156+
)
157+
151158
log = har.get_log()
152-
assert len(log["pages"]) == 1
159+
assert len(log["pages"]) == 2
153160
page_entry = log["pages"][0]
154161
assert page_entry["id"]
155162
assert page_entry["title"] == "Hello"

0 commit comments

Comments
 (0)