Skip to content

feat: added BrowserType.connect_over_cdp #640

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
1 change: 1 addition & 0 deletions local-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pytest-cov==2.11.1
pytest-sugar==0.9.4
pytest-timeout==1.4.2
pytest-xdist==2.2.1
requests==2.25.1
service_identity==18.1.0
setuptools==54.0.0
twine==3.3.0
Expand Down
29 changes: 27 additions & 2 deletions playwright/_impl/_browser_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

from pathlib import Path
from typing import Dict, List, Union
from typing import Dict, List, Optional, Union, cast

from playwright._impl._api_structures import (
Geolocation,
Expand All @@ -23,7 +23,11 @@
)
from playwright._impl._browser import Browser, normalize_context_params
from playwright._impl._browser_context import BrowserContext
from playwright._impl._connection import ChannelOwner, from_channel
from playwright._impl._connection import (
ChannelOwner,
from_channel,
from_nullable_channel,
)
from playwright._impl._helper import (
BrowserChannel,
ColorScheme,
Expand Down Expand Up @@ -135,6 +139,27 @@ async def launch_persistent_context(
raise not_installed_error(f'"{self.name}" browser was not found.')
raise e

async def connect_over_cdp(
self, endpointURL: str, timeout: float = None, slow_mo: float = None
) -> Browser:
params = locals_to_params(locals())
params["sdkLanguage"] = (
"python" if self._connection._is_sync else "python-async"
)
response = await self._channel.send_return_as_dict("connectOverCDP", params)
browser = cast(Browser, from_channel(response["browser"]))
browser._is_remote = True

default_context = cast(
Optional[BrowserContext],
from_nullable_channel(response.get("defaultContext")),
)
if default_context:
browser._contexts.append(default_context)
default_context._browser = browser

return browser


def normalize_launch_params(params: Dict) -> None:
if "env" in params:
Expand Down
6 changes: 6 additions & 0 deletions playwright/_impl/_element_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ async def hover(
position: Position = None,
timeout: float = None,
force: bool = None,
trial: bool = None,
) -> None:
await self._channel.send("hover", locals_to_params(locals()))

Expand All @@ -117,6 +118,7 @@ async def click(
timeout: float = None,
force: bool = None,
noWaitAfter: bool = None,
trial: bool = None,
) -> None:
await self._channel.send("click", locals_to_params(locals()))

Expand All @@ -129,6 +131,7 @@ async def dblclick(
timeout: float = None,
force: bool = None,
noWaitAfter: bool = None,
trial: bool = None,
) -> None:
await self._channel.send("dblclick", locals_to_params(locals()))

Expand Down Expand Up @@ -157,6 +160,7 @@ async def tap(
timeout: float = None,
force: bool = None,
noWaitAfter: bool = None,
trial: bool = None,
) -> None:
await self._channel.send("tap", locals_to_params(locals()))

Expand Down Expand Up @@ -205,6 +209,7 @@ async def check(
timeout: float = None,
force: bool = None,
noWaitAfter: bool = None,
trial: bool = None,
) -> None:
await self._channel.send("check", locals_to_params(locals()))

Expand All @@ -214,6 +219,7 @@ async def uncheck(
timeout: float = None,
force: bool = None,
noWaitAfter: bool = None,
trial: bool = None,
) -> None:
await self._channel.send("uncheck", locals_to_params(locals()))

Expand Down
6 changes: 6 additions & 0 deletions playwright/_impl/_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ async def click(
timeout: float = None,
force: bool = None,
noWaitAfter: bool = None,
trial: bool = None,
) -> None:
await self._channel.send("click", locals_to_params(locals()))

Expand All @@ -401,6 +402,7 @@ async def dblclick(
timeout: float = None,
force: bool = None,
noWaitAfter: bool = None,
trial: bool = None,
) -> None:
await self._channel.send("dblclick", locals_to_params(locals()))

Expand All @@ -412,6 +414,7 @@ async def tap(
timeout: float = None,
force: bool = None,
noWaitAfter: bool = None,
trial: bool = None,
) -> None:
await self._channel.send("tap", locals_to_params(locals()))

Expand Down Expand Up @@ -444,6 +447,7 @@ async def hover(
position: Position = None,
timeout: float = None,
force: bool = None,
trial: bool = None,
) -> None:
await self._channel.send("hover", locals_to_params(locals()))

Expand Down Expand Up @@ -505,6 +509,7 @@ async def check(
timeout: float = None,
force: bool = None,
noWaitAfter: bool = None,
trial: bool = None,
) -> None:
await self._channel.send("check", locals_to_params(locals()))

Expand All @@ -515,6 +520,7 @@ async def uncheck(
timeout: float = None,
force: bool = None,
noWaitAfter: bool = None,
trial: bool = None,
) -> None:
await self._channel.send("uncheck", locals_to_params(locals()))

Expand Down
2 changes: 1 addition & 1 deletion playwright/_impl/_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def parse_error(error: ErrorPayload) -> Error:


def patch_error_message(message: Optional[str]) -> Optional[str]:
if not message:
if message is None:
return None

match = re.match(r"(\w+)(: expected .*)", message)
Expand Down
6 changes: 6 additions & 0 deletions playwright/_impl/_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@ async def click(
timeout: float = None,
force: bool = None,
noWaitAfter: bool = None,
trial: bool = None,
) -> None:
return await self._main_frame.click(**locals_to_params(locals()))

Expand All @@ -621,6 +622,7 @@ async def dblclick(
timeout: float = None,
force: bool = None,
noWaitAfter: bool = None,
trial: bool = None,
) -> None:
return await self._main_frame.dblclick(**locals_to_params(locals()))

Expand All @@ -632,6 +634,7 @@ async def tap(
timeout: float = None,
force: bool = None,
noWaitAfter: bool = None,
trial: bool = None,
) -> None:
return await self._main_frame.tap(**locals_to_params(locals()))

Expand Down Expand Up @@ -664,6 +667,7 @@ async def hover(
position: Position = None,
timeout: float = None,
force: bool = None,
trial: bool = None,
) -> None:
return await self._main_frame.hover(**locals_to_params(locals()))

Expand Down Expand Up @@ -716,6 +720,7 @@ async def check(
timeout: float = None,
force: bool = None,
noWaitAfter: bool = None,
trial: bool = None,
) -> None:
return await self._main_frame.check(**locals_to_params(locals()))

Expand All @@ -726,6 +731,7 @@ async def uncheck(
timeout: float = None,
force: bool = None,
noWaitAfter: bool = None,
trial: bool = None,
) -> None:
return await self._main_frame.uncheck(**locals_to_params(locals()))

Expand Down
Loading