Skip to content
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 DRIVER_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
a018f24a4fc76e2120d3b35d2415f1e5bd4b073e
049226728d2da8054db18b04782a9848b755855e
12 changes: 0 additions & 12 deletions playwright/_impl/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,18 +386,6 @@ async def evaluate(self, expression: str, arg: Serializable) -> Any:
)
return parse_result(result["value"])

async def _evaluate_expose_utility_script(
self, expression: str, arg: Serializable
) -> Any:
result = await self._channel.evaluateExpression(
expression=expression,
# Python: undefined; see the docstring of js_handle.py.
isFunction=None,
arg=serialize_argument(arg),
timeout=NO_TIMEOUT,
)
return parse_result(result["value"])

async def query_selector(
self, selector: str, strict: Optional[bool]
) -> Optional[ElementHandle]:
Expand Down
34 changes: 31 additions & 3 deletions playwright/async_api/_generated.py
Original file line number Diff line number Diff line change
Expand Up @@ -4017,13 +4017,41 @@ async def connect_over_cdp(
A CDP websocket endpoint or http url to connect to. For example `http://localhost:9222/` or
`ws://127.0.0.1:9222/devtools/browser/387adf4c-243f-4051-a181-46798f4a46f4`.

Alternatively, a browser channel name such as `chrome` or `msedge` to connect to a browser with remote debugging
enabled in its default user data directory. On Linux, Playwright uses `CHROME_USER_DATA_DIR` when set. Otherwise,
it uses `CHROME_CONFIG_HOME`, then `XDG_CONFIG_HOME`, then `~/.config` to locate that directory.
Alternatively, a URL that tells which running browser to connect to:
- `remote-debugging://<channel>` - a browser with remote debugging enabled, for example
`remote-debugging://msedge`. The optional `userDataDir` parameter is the user data directory of the browser,
when it is not the default one: `remote-debugging://chrome?userDataDir=/path/to/data`. A bare channel name such
as `chrome` is the same as `remote-debugging://chrome`.
- `extension://<channel>/<profile directory>` - the tabs of a browser profile, through the
[Playwright Extension](https://chromewebstore.google.com/detail/playwright-extension/mmlmfjhmonkocbjadbfplnigmagldckm),
for example `extension://chrome/Profile 1`. Playwright opens the connect page of the extension in that profile,
and the user selects the tabs to share. Without the profile directory, Playwright uses the `Default` profile.
The optional parameters are `userDataDir`, the user data directory of the browser when it is not the default
one, and `executablePath`, the path to the browser executable when it is not at the standard location:
`extension://chromium?executablePath=/path/to/chrome&userDataDir=/path/to/data`. Pass the other options of this
connection in `headers`.

The values of `userDataDir` and `executablePath` must be URL-encoded, for example with `encodeURIComponent` or
`URLSearchParams`. The channel is a browser channel name such as `chrome`, `chrome-beta` or `msedge`. The default
user data directory of the channel is where the browser keeps its data. On Linux, Playwright uses
`CHROME_USER_DATA_DIR` when set. Otherwise, it uses `CHROME_CONFIG_HOME`, then `XDG_CONFIG_HOME`, then `~/.config`
to locate that directory.
artifacts_dir : Union[pathlib.Path, str, None]
If specified, browser artifacts (such as traces and downloads) are saved into this directory.
headers : Union[Dict[str, str], None]
Additional HTTP headers to be sent with connect request. Optional.

When `endpoint_url` is an extension URL such as `extension://chrome`, the headers are not sent. They are the
options of the connection:
- `x-playwright-extension-token` - the token of the extension. With the token, the user does not have to approve
the connection. Without the token, the user must approve the connection before `timeout` expires, so set it to
a value that gives the user enough time.
- `x-playwright-extension-client-name` - the name of the client that the extension shows to the user.
- `x-playwright-extension-tab-group` - pass `false` to keep the tabs out of a tab group.
- `x-playwright-extension-tab-group-title` - the title of the tab group.
- `x-playwright-extension-tab-group-color` - the color of the tab group: `green`, `blue`, `purple`, `orange`,
`pink`, `cyan`, `yellow` or `red`.
- `x-playwright-extension-background` - pass `true` to keep the tabs from becoming active.
is_local : Union[bool, None]
Tells Playwright that it runs on the same host as the CDP server. It will enable certain optimizations that rely
upon the file system being the same between Playwright and the Browser.
Expand Down
34 changes: 31 additions & 3 deletions playwright/sync_api/_generated.py
Original file line number Diff line number Diff line change
Expand Up @@ -3943,13 +3943,41 @@ def connect_over_cdp(
A CDP websocket endpoint or http url to connect to. For example `http://localhost:9222/` or
`ws://127.0.0.1:9222/devtools/browser/387adf4c-243f-4051-a181-46798f4a46f4`.

Alternatively, a browser channel name such as `chrome` or `msedge` to connect to a browser with remote debugging
enabled in its default user data directory. On Linux, Playwright uses `CHROME_USER_DATA_DIR` when set. Otherwise,
it uses `CHROME_CONFIG_HOME`, then `XDG_CONFIG_HOME`, then `~/.config` to locate that directory.
Alternatively, a URL that tells which running browser to connect to:
- `remote-debugging://<channel>` - a browser with remote debugging enabled, for example
`remote-debugging://msedge`. The optional `userDataDir` parameter is the user data directory of the browser,
when it is not the default one: `remote-debugging://chrome?userDataDir=/path/to/data`. A bare channel name such
as `chrome` is the same as `remote-debugging://chrome`.
- `extension://<channel>/<profile directory>` - the tabs of a browser profile, through the
[Playwright Extension](https://chromewebstore.google.com/detail/playwright-extension/mmlmfjhmonkocbjadbfplnigmagldckm),
for example `extension://chrome/Profile 1`. Playwright opens the connect page of the extension in that profile,
and the user selects the tabs to share. Without the profile directory, Playwright uses the `Default` profile.
The optional parameters are `userDataDir`, the user data directory of the browser when it is not the default
one, and `executablePath`, the path to the browser executable when it is not at the standard location:
`extension://chromium?executablePath=/path/to/chrome&userDataDir=/path/to/data`. Pass the other options of this
connection in `headers`.

The values of `userDataDir` and `executablePath` must be URL-encoded, for example with `encodeURIComponent` or
`URLSearchParams`. The channel is a browser channel name such as `chrome`, `chrome-beta` or `msedge`. The default
user data directory of the channel is where the browser keeps its data. On Linux, Playwright uses
`CHROME_USER_DATA_DIR` when set. Otherwise, it uses `CHROME_CONFIG_HOME`, then `XDG_CONFIG_HOME`, then `~/.config`
to locate that directory.
artifacts_dir : Union[pathlib.Path, str, None]
If specified, browser artifacts (such as traces and downloads) are saved into this directory.
headers : Union[Dict[str, str], None]
Additional HTTP headers to be sent with connect request. Optional.

When `endpoint_url` is an extension URL such as `extension://chrome`, the headers are not sent. They are the
options of the connection:
- `x-playwright-extension-token` - the token of the extension. With the token, the user does not have to approve
the connection. Without the token, the user must approve the connection before `timeout` expires, so set it to
a value that gives the user enough time.
- `x-playwright-extension-client-name` - the name of the client that the extension shows to the user.
- `x-playwright-extension-tab-group` - pass `false` to keep the tabs out of a tab group.
- `x-playwright-extension-tab-group-title` - the title of the tab group.
- `x-playwright-extension-tab-group-color` - the color of the tab group: `green`, `blue`, `purple`, `orange`,
`pink`, `cyan`, `yellow` or `red`.
- `x-playwright-extension-background` - pass `true` to keep the tabs from becoming active.
is_local : Union[bool, None]
Tells Playwright that it runs on the same host as the CDP server. It will enable certain optimizations that rely
upon the file system being the same between Playwright and the Browser.
Expand Down
8 changes: 8 additions & 0 deletions tests/async/library/chromium/test_connect_over_cdp.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import os
import signal
import sys
import urllib.parse
import urllib.request
from contextlib import suppress
from pathlib import Path
Expand Down Expand Up @@ -105,6 +106,13 @@ async def test_CD_001_should_connect_to_an_existing_cdp_session(
assert len(contexts) == 1
await cdp_browser.close()

url_browser = await browser_type.connect_over_cdp(
"remote-debugging://chromium?"
+ urllib.parse.urlencode({"userDataDir": str(user_data_dir)})
)
assert len(url_browser.contexts) == 1
await url_browser.close()

if is_linux:
environments: List[Dict[str, Optional[str]]] = [
{
Expand Down
28 changes: 28 additions & 0 deletions tests/async/library/test_browsertype_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
from tests.helpers.remote_server import (
KIND_LAUNCH_SERVER,
KIND_RUN_SERVER,
ChildProcess,
RemoteServerStarter,
RunServer,
redirect_port_forwarding_for_test,
Expand All @@ -65,6 +66,21 @@
KINDS = [KIND_LAUNCH_SERVER, KIND_RUN_SERVER]


@pytest.fixture
def child_process() -> Generator[Callable[..., ChildProcess], None, None]:
"""Port of the childProcess fixture in tests/config/commonFixtures.ts."""
processes: List[ChildProcess] = []

def start(command: List[str]) -> ChildProcess:
process = ChildProcess(command)
processes.append(process)
return process

yield start
for process in processes:
process.kill()


async def connect_browser(
browser_type: BrowserType,
launch_arguments: Dict,
Expand Down Expand Up @@ -1823,6 +1839,18 @@ async def test_BT_093_should_refuse_connecting_when_versions_do_not_match(
assert "client version: v" + client_version() in exc_info.value.message


async def test_BT_105_run_server_should_exit_when_stdin_closes(
child_process: Callable[..., ChildProcess],
) -> None:
node, cli = compute_driver_executable()
server = child_process([node, cli, "run-server", "--port=0"])
await asyncio.to_thread(server.wait_for_output, "Listening on ")
assert server.process.stdin
server.process.stdin.close()
# Python: a zero return code means exitCode: 0 and signal: null.
assert await asyncio.to_thread(server.exit_code) == 0


async def test_BT_094_should_filter_local_paths_from_unsafe_launch_options(
connect: Callable[..., Awaitable[Browser]],
start_remote_server: RemoteServerStarter,
Expand Down
9 changes: 8 additions & 1 deletion tests/async/library/test_har.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,15 @@ async def test_HA_003_should_have_pages(page_with_har: PageWithHar) -> None:
await har.page.goto("data:text/html,<title>Hello</title>")
# For data: load comes before domcontentloaded...
await har.page.wait_for_load_state("domcontentloaded")

page_with_dialog = await har.page.context.new_page()
async with page_with_dialog.expect_event("dialog"):
await page_with_dialog.goto(
'data:text/html,<body onload="alert(1)">', wait_until="commit"
)

log = await har.get_log()
assert len(log["pages"]) == 1
assert len(log["pages"]) == 2
page_entry = log["pages"][0]
assert page_entry["id"]
assert page_entry["title"] == "Hello"
Expand Down
8 changes: 8 additions & 0 deletions tests/sync/library/chromium/test_connect_over_cdp.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import signal
import sys
import time
import urllib.parse
import urllib.request
from concurrent.futures import ThreadPoolExecutor
from contextlib import suppress
Expand Down Expand Up @@ -117,6 +118,13 @@ def test_CD_001_should_connect_to_an_existing_cdp_session(
assert len(contexts) == 1
cdp_browser.close()

url_browser = browser_type.connect_over_cdp(
"remote-debugging://chromium?"
+ urllib.parse.urlencode({"userDataDir": str(user_data_dir)})
)
assert len(url_browser.contexts) == 1
url_browser.close()

if is_linux:
environments: List[Dict[str, Optional[str]]] = [
{
Expand Down
28 changes: 28 additions & 0 deletions tests/sync/library/test_browsertype_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
from tests.helpers.remote_server import (
KIND_LAUNCH_SERVER,
KIND_RUN_SERVER,
ChildProcess,
RemoteServerStarter,
RunServer,
redirect_port_forwarding_for_test,
Expand All @@ -58,6 +59,21 @@
KINDS = [KIND_LAUNCH_SERVER, KIND_RUN_SERVER]


@pytest.fixture
def child_process() -> Generator[Callable[..., ChildProcess], None, None]:
"""Port of the childProcess fixture in tests/config/commonFixtures.ts."""
processes: List[ChildProcess] = []

def start(command: List[str]) -> ChildProcess:
process = ChildProcess(command)
processes.append(process)
return process

yield start
for process in processes:
process.kill()


def connect_browser(
browser_type: BrowserType,
launch_arguments: Dict,
Expand Down Expand Up @@ -1848,6 +1864,18 @@ def test_BT_093_should_refuse_connecting_when_versions_do_not_match(
assert "client version: v" + client_version() in exc_info.value.message


def test_BT_105_run_server_should_exit_when_stdin_closes(
child_process: Callable[..., ChildProcess],
) -> None:
node, cli = compute_driver_executable()
server = child_process([node, cli, "run-server", "--port=0"])
server.wait_for_output("Listening on ")
assert server.process.stdin
server.process.stdin.close()
# Python: a zero return code means exitCode: 0 and signal: null.
assert server.exit_code() == 0


def test_BT_094_should_filter_local_paths_from_unsafe_launch_options(
connect: Callable[..., Browser],
start_remote_server: RemoteServerStarter,
Expand Down
9 changes: 8 additions & 1 deletion tests/sync/library/test_har.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,15 @@ def test_HA_003_should_have_pages(page_with_har: PageWithHar) -> None:
har.page.goto("data:text/html,<title>Hello</title>")
# For data: load comes before domcontentloaded...
har.page.wait_for_load_state("domcontentloaded")

page_with_dialog = har.page.context.new_page()
with page_with_dialog.expect_event("dialog"):
page_with_dialog.goto(
'data:text/html,<body onload="alert(1)">', wait_until="commit"
)

log = har.get_log()
assert len(log["pages"]) == 1
assert len(log["pages"]) == 2
page_entry = log["pages"][0]
assert page_entry["id"]
assert page_entry["title"] == "Hello"
Expand Down
1 change: 1 addition & 0 deletions tests/upstream_registry.md
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,7 @@ subsystem, add a row to the Subsystems table. Then update this file:
| `BT-102` | `library/browsertype-launch-selenium.spec.ts` | selenium grid 3.141.59 standalone non-chromium |
| `BT-103` | `library/browsertype-launch-selenium.spec.ts` | selenium grid 3.141.59 standalone chromium through run-driver |
| `BT-104` | `library/browsertype-launch-server.spec.ts` | launch server › should handle timeout |
| `BT-105` | `library/browsertype-connect.spec.ts` | run-server should exit when stdin closes |

### BU — Before unload

Expand Down
Loading