playwright-browserstack 1.62.0__py3-none-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- playwright/__init__.py +19 -0
- playwright/__main__.py +33 -0
- playwright/_impl/__init__.py +0 -0
- playwright/_impl/__pyinstaller/__init__.py +20 -0
- playwright/_impl/__pyinstaller/hook-playwright.async_api.py +17 -0
- playwright/_impl/__pyinstaller/hook-playwright.sync_api.py +17 -0
- playwright/_impl/_android.py +704 -0
- playwright/_impl/_api_structures.py +365 -0
- playwright/_impl/_artifact.py +87 -0
- playwright/_impl/_assertions.py +1124 -0
- playwright/_impl/_async_base.py +105 -0
- playwright/_impl/_browser.py +293 -0
- playwright/_impl/_browser_context.py +754 -0
- playwright/_impl/_browser_type.py +368 -0
- playwright/_impl/_cdp_session.py +46 -0
- playwright/_impl/_clock.py +104 -0
- playwright/_impl/_connection.py +764 -0
- playwright/_impl/_console_message.py +98 -0
- playwright/_impl/_credentials.py +57 -0
- playwright/_impl/_debugger.py +54 -0
- playwright/_impl/_dialog.py +63 -0
- playwright/_impl/_disposable.py +96 -0
- playwright/_impl/_download.py +64 -0
- playwright/_impl/_driver.py +41 -0
- playwright/_impl/_element_handle.py +480 -0
- playwright/_impl/_errors.py +64 -0
- playwright/_impl/_event_context_manager.py +33 -0
- playwright/_impl/_fetch.py +626 -0
- playwright/_impl/_file_chooser.py +57 -0
- playwright/_impl/_form_data.py +34 -0
- playwright/_impl/_frame.py +985 -0
- playwright/_impl/_glob.py +65 -0
- playwright/_impl/_greenlets.py +49 -0
- playwright/_impl/_har_router.py +122 -0
- playwright/_impl/_helper.py +601 -0
- playwright/_impl/_impl_to_api_mapping.py +158 -0
- playwright/_impl/_input.py +111 -0
- playwright/_impl/_js_handle.py +336 -0
- playwright/_impl/_json_pipe.py +97 -0
- playwright/_impl/_local_utils.py +95 -0
- playwright/_impl/_locator.py +1024 -0
- playwright/_impl/_map.py +31 -0
- playwright/_impl/_network.py +1017 -0
- playwright/_impl/_object_factory.py +116 -0
- playwright/_impl/_page.py +1637 -0
- playwright/_impl/_path_utils.py +27 -0
- playwright/_impl/_playwright.py +68 -0
- playwright/_impl/_screencast.py +177 -0
- playwright/_impl/_selectors.py +67 -0
- playwright/_impl/_set_input_files_helpers.py +158 -0
- playwright/_impl/_str_utils.py +76 -0
- playwright/_impl/_stream.py +46 -0
- playwright/_impl/_sync_base.py +151 -0
- playwright/_impl/_tracing.py +281 -0
- playwright/_impl/_transport.py +184 -0
- playwright/_impl/_video.py +56 -0
- playwright/_impl/_waiter.py +197 -0
- playwright/_impl/_web_error.py +48 -0
- playwright/_impl/_web_storage.py +58 -0
- playwright/_impl/_writable_stream.py +42 -0
- playwright/_repo_version.py +24 -0
- playwright/async_api/__init__.py +275 -0
- playwright/async_api/_android_generated.py +462 -0
- playwright/async_api/_context_manager.py +57 -0
- playwright/async_api/_generated.py +23875 -0
- playwright/driver/LICENSE +2946 -0
- playwright/driver/README.md +1 -0
- playwright/driver/node.exe +0 -0
- playwright/driver/package/LICENSE +202 -0
- playwright/driver/package/NOTICE +5 -0
- playwright/driver/package/README.md +3 -0
- playwright/driver/package/ThirdPartyNotices.txt +13 -0
- playwright/driver/package/bin/install_media_pack.ps1 +5 -0
- playwright/driver/package/bin/install_webkit_wsl.ps1 +33 -0
- playwright/driver/package/bin/reinstall_chrome_beta_linux.sh +42 -0
- playwright/driver/package/bin/reinstall_chrome_beta_mac.sh +13 -0
- playwright/driver/package/bin/reinstall_chrome_beta_win.ps1 +24 -0
- playwright/driver/package/bin/reinstall_chrome_stable_linux.sh +42 -0
- playwright/driver/package/bin/reinstall_chrome_stable_mac.sh +12 -0
- playwright/driver/package/bin/reinstall_chrome_stable_win.ps1 +24 -0
- playwright/driver/package/bin/reinstall_msedge_beta_linux.sh +48 -0
- playwright/driver/package/bin/reinstall_msedge_beta_mac.sh +11 -0
- playwright/driver/package/bin/reinstall_msedge_beta_win.ps1 +23 -0
- playwright/driver/package/bin/reinstall_msedge_dev_linux.sh +48 -0
- playwright/driver/package/bin/reinstall_msedge_dev_mac.sh +11 -0
- playwright/driver/package/bin/reinstall_msedge_dev_win.ps1 +23 -0
- playwright/driver/package/bin/reinstall_msedge_stable_linux.sh +48 -0
- playwright/driver/package/bin/reinstall_msedge_stable_mac.sh +11 -0
- playwright/driver/package/bin/reinstall_msedge_stable_win.ps1 +24 -0
- playwright/driver/package/browsers.json +75 -0
- playwright/driver/package/cli.js +21 -0
- playwright/driver/package/index.d.ts +17 -0
- playwright/driver/package/index.js +17 -0
- playwright/driver/package/index.mjs +28 -0
- playwright/driver/package/lib/bootstrap.js +88 -0
- playwright/driver/package/lib/coreBundle.js +74830 -0
- playwright/driver/package/lib/entry/cliDaemon.js +5 -0
- playwright/driver/package/lib/entry/dashboardApp.js +3 -0
- playwright/driver/package/lib/entry/mcp.js +10 -0
- playwright/driver/package/lib/entry/oopBrowserDownload.js +3 -0
- playwright/driver/package/lib/package.js +50 -0
- playwright/driver/package/lib/server/chromium/appIcon.png +0 -0
- playwright/driver/package/lib/server/electron/loader.js +118 -0
- playwright/driver/package/lib/serverRegistry.js +7347 -0
- playwright/driver/package/lib/serverRegistry.js.LICENSE +354 -0
- playwright/driver/package/lib/tools/cli-client/channelSessions.js +141 -0
- playwright/driver/package/lib/tools/cli-client/cli.js +6 -0
- playwright/driver/package/lib/tools/cli-client/help.json +708 -0
- playwright/driver/package/lib/tools/cli-client/minimist.js +128 -0
- playwright/driver/package/lib/tools/cli-client/output.js +343 -0
- playwright/driver/package/lib/tools/cli-client/program.js +404 -0
- playwright/driver/package/lib/tools/cli-client/registry.js +176 -0
- playwright/driver/package/lib/tools/cli-client/session.js +258 -0
- playwright/driver/package/lib/tools/dashboard/appIcon.png +0 -0
- playwright/driver/package/lib/tools/skills/playwright-cli/SKILL.md +420 -0
- playwright/driver/package/lib/tools/skills/playwright-cli/references/element-attributes.md +23 -0
- playwright/driver/package/lib/tools/skills/playwright-cli/references/playwright-tests.md +39 -0
- playwright/driver/package/lib/tools/skills/playwright-cli/references/request-mocking.md +87 -0
- playwright/driver/package/lib/tools/skills/playwright-cli/references/running-code.md +241 -0
- playwright/driver/package/lib/tools/skills/playwright-cli/references/session-management.md +225 -0
- playwright/driver/package/lib/tools/skills/playwright-cli/references/storage-state.md +275 -0
- playwright/driver/package/lib/tools/skills/playwright-cli/references/test-generation.md +433 -0
- playwright/driver/package/lib/tools/skills/playwright-cli/references/tracing.md +139 -0
- playwright/driver/package/lib/tools/skills/playwright-cli/references/video-recording.md +143 -0
- playwright/driver/package/lib/tools/skills/playwright-component-testing/SKILL.md +143 -0
- playwright/driver/package/lib/tools/skills/playwright-component-testing/references/gallery-spec.md +144 -0
- playwright/driver/package/lib/tools/skills/playwright-component-testing/references/migration.md +85 -0
- playwright/driver/package/lib/tools/skills/playwright-component-testing/references/react.md +67 -0
- playwright/driver/package/lib/tools/skills/playwright-component-testing/references/vue.md +75 -0
- playwright/driver/package/lib/tools/skills/playwright-trace/SKILL.md +171 -0
- playwright/driver/package/lib/tools/utils/extension.js +101 -0
- playwright/driver/package/lib/tools/utils/socketConnection.js +108 -0
- playwright/driver/package/lib/utilsBundle.js +90764 -0
- playwright/driver/package/lib/utilsBundle.js.LICENSE +2179 -0
- playwright/driver/package/lib/vite/dashboard/assets/codicon-DCmgc-ay.ttf +0 -0
- playwright/driver/package/lib/vite/dashboard/assets/firefox-1bWoP6pv.svg +1 -0
- playwright/driver/package/lib/vite/dashboard/assets/firefox-beta-k3eOH_eK.svg +1 -0
- playwright/driver/package/lib/vite/dashboard/assets/firefox-nightly-Cp5nfeDT.svg +1 -0
- playwright/driver/package/lib/vite/dashboard/assets/index-CyWAfh-p.js +11 -0
- playwright/driver/package/lib/vite/dashboard/assets/index-DhC616m4.css +1 -0
- playwright/driver/package/lib/vite/dashboard/assets/safari-na3_-uQk.svg +1 -0
- playwright/driver/package/lib/vite/dashboard/index.html +29 -0
- playwright/driver/package/lib/vite/dashboard/playwright-logo.svg +24 -0
- playwright/driver/package/lib/vite/htmlReport/index.html +16 -0
- playwright/driver/package/lib/vite/htmlReport/report.css +2 -0
- playwright/driver/package/lib/vite/htmlReport/report.js +32 -0
- playwright/driver/package/lib/vite/recorder/assets/codeMirrorModule--QdMvsKi.css +1 -0
- playwright/driver/package/lib/vite/recorder/assets/codeMirrorModule-CwYYHbcZ.js +32 -0
- playwright/driver/package/lib/vite/recorder/assets/codicon-DCmgc-ay.ttf +0 -0
- playwright/driver/package/lib/vite/recorder/assets/index-DYjdXIbE.js +129 -0
- playwright/driver/package/lib/vite/recorder/assets/index-l_lX622x.css +1 -0
- playwright/driver/package/lib/vite/recorder/index.html +29 -0
- playwright/driver/package/lib/vite/recorder/playwright-logo.svg +9 -0
- playwright/driver/package/lib/vite/traceViewer/assets/codeMirrorModule-By56iMx7.js +32 -0
- playwright/driver/package/lib/vite/traceViewer/assets/defaultSettingsView-B34OrIms.js +181 -0
- playwright/driver/package/lib/vite/traceViewer/assets/urlMatch-L3liM589.js +1 -0
- playwright/driver/package/lib/vite/traceViewer/assets/xtermModule-COQkjINf.js +7 -0
- playwright/driver/package/lib/vite/traceViewer/codeMirrorModule.-QdMvsKi.css +1 -0
- playwright/driver/package/lib/vite/traceViewer/codicon.DCmgc-ay.ttf +0 -0
- playwright/driver/package/lib/vite/traceViewer/defaultSettingsView.BLFoOugd.css +1 -0
- playwright/driver/package/lib/vite/traceViewer/index.B_TqY17P.css +1 -0
- playwright/driver/package/lib/vite/traceViewer/index.Dl36UVQT.js +1 -0
- playwright/driver/package/lib/vite/traceViewer/index.html +44 -0
- playwright/driver/package/lib/vite/traceViewer/manifest.webmanifest +16 -0
- playwright/driver/package/lib/vite/traceViewer/playwright-logo.svg +9 -0
- playwright/driver/package/lib/vite/traceViewer/snapshot.B_Jk1wbt.js +1 -0
- playwright/driver/package/lib/vite/traceViewer/snapshot.html +10 -0
- playwright/driver/package/lib/vite/traceViewer/sw.bundle.js +4 -0
- playwright/driver/package/lib/vite/traceViewer/uiMode.C7UW1sC9.css +1 -0
- playwright/driver/package/lib/vite/traceViewer/uiMode.D962mr9b.js +5 -0
- playwright/driver/package/lib/vite/traceViewer/uiMode.html +18 -0
- playwright/driver/package/lib/vite/traceViewer/xtermModule.kHJ-D0s7.css +1 -0
- playwright/driver/package/lib/webp_codec.LICENSE +173 -0
- playwright/driver/package/lib/webp_codec.wasm +0 -0
- playwright/driver/package/lib/xdg-open +1267 -0
- playwright/driver/package/package.json +34 -0
- playwright/driver/package/types/protocol.d.ts +24842 -0
- playwright/driver/package/types/structs.d.ts +47 -0
- playwright/driver/package/types/types.d.ts +26188 -0
- playwright/py.typed +0 -0
- playwright/sync_api/__init__.py +275 -0
- playwright/sync_api/_android_generated.py +494 -0
- playwright/sync_api/_context_manager.py +98 -0
- playwright/sync_api/_generated.py +24045 -0
- playwright_browserstack-1.62.0.dist-info/METADATA +82 -0
- playwright_browserstack-1.62.0.dist-info/RECORD +192 -0
- playwright_browserstack-1.62.0.dist-info/WHEEL +5 -0
- playwright_browserstack-1.62.0.dist-info/entry_points.txt +5 -0
- playwright_browserstack-1.62.0.dist-info/licenses/LICENSE +202 -0
- playwright_browserstack-1.62.0.dist-info/licenses/LICENSE.txt +51 -0
- playwright_browserstack-1.62.0.dist-info/licenses/NOTICE +18 -0
- playwright_browserstack-1.62.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,105 @@
|
|
|
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
|
+
import asyncio
|
|
16
|
+
from contextlib import AbstractAsyncContextManager
|
|
17
|
+
from types import TracebackType
|
|
18
|
+
from typing import Any, Callable, Generic, Optional, Type, TypeVar, Union
|
|
19
|
+
|
|
20
|
+
from playwright._impl._impl_to_api_mapping import ImplToApiMapping, ImplWrapper
|
|
21
|
+
|
|
22
|
+
mapping = ImplToApiMapping()
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
T = TypeVar("T")
|
|
26
|
+
Self = TypeVar("Self", bound="AsyncContextManager")
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class AsyncEventInfo(Generic[T]):
|
|
30
|
+
def __init__(self, future: "asyncio.Future[T]") -> None:
|
|
31
|
+
self._future = future
|
|
32
|
+
|
|
33
|
+
@property
|
|
34
|
+
async def value(self) -> T:
|
|
35
|
+
return mapping.from_maybe_impl(await self._future)
|
|
36
|
+
|
|
37
|
+
def _cancel(self) -> None:
|
|
38
|
+
self._future.cancel()
|
|
39
|
+
|
|
40
|
+
def is_done(self) -> bool:
|
|
41
|
+
return self._future.done()
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class AsyncEventContextManager(Generic[T], AbstractAsyncContextManager):
|
|
45
|
+
def __init__(self, future: "asyncio.Future[T]") -> None:
|
|
46
|
+
self._event = AsyncEventInfo[T](future)
|
|
47
|
+
|
|
48
|
+
async def __aenter__(self) -> AsyncEventInfo[T]:
|
|
49
|
+
return self._event
|
|
50
|
+
|
|
51
|
+
async def __aexit__(
|
|
52
|
+
self,
|
|
53
|
+
exc_type: Optional[Type[BaseException]],
|
|
54
|
+
exc_val: Optional[BaseException],
|
|
55
|
+
exc_tb: Optional[TracebackType],
|
|
56
|
+
) -> None:
|
|
57
|
+
if exc_val:
|
|
58
|
+
self._event._cancel()
|
|
59
|
+
else:
|
|
60
|
+
await self._event.value
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class AsyncBase(ImplWrapper):
|
|
64
|
+
def __init__(self, impl_obj: Any) -> None:
|
|
65
|
+
super().__init__(impl_obj)
|
|
66
|
+
self._loop = impl_obj._loop
|
|
67
|
+
|
|
68
|
+
def __str__(self) -> str:
|
|
69
|
+
return self._impl_obj.__str__()
|
|
70
|
+
|
|
71
|
+
def _wrap_handler(
|
|
72
|
+
self, handler: Union[Callable[..., Any], Any]
|
|
73
|
+
) -> Callable[..., None]:
|
|
74
|
+
if callable(handler):
|
|
75
|
+
return mapping.wrap_handler(handler)
|
|
76
|
+
return handler
|
|
77
|
+
|
|
78
|
+
def on(self, event: Any, f: Any) -> None:
|
|
79
|
+
"""Registers the function ``f`` to the event name ``event``."""
|
|
80
|
+
self._impl_obj.on(event, self._wrap_handler(f))
|
|
81
|
+
|
|
82
|
+
def once(self, event: Any, f: Any) -> None:
|
|
83
|
+
"""The same as ``self.on``, except that the listener is automatically
|
|
84
|
+
removed after being called.
|
|
85
|
+
"""
|
|
86
|
+
self._impl_obj.once(event, self._wrap_handler(f))
|
|
87
|
+
|
|
88
|
+
def remove_listener(self, event: Any, f: Any) -> None:
|
|
89
|
+
"""Removes the function ``f`` from ``event``."""
|
|
90
|
+
self._impl_obj.remove_listener(event, self._wrap_handler(f))
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class AsyncContextManager(AsyncBase):
|
|
94
|
+
async def __aenter__(self: Self) -> Self:
|
|
95
|
+
return self
|
|
96
|
+
|
|
97
|
+
async def __aexit__(
|
|
98
|
+
self,
|
|
99
|
+
exc_type: Optional[Type[BaseException]],
|
|
100
|
+
exc_val: Optional[BaseException],
|
|
101
|
+
traceback: Optional[TracebackType],
|
|
102
|
+
) -> None:
|
|
103
|
+
await self.close()
|
|
104
|
+
|
|
105
|
+
async def close(self) -> None: ...
|
|
@@ -0,0 +1,293 @@
|
|
|
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 pathlib import Path
|
|
16
|
+
from types import SimpleNamespace
|
|
17
|
+
from typing import (
|
|
18
|
+
TYPE_CHECKING,
|
|
19
|
+
Dict,
|
|
20
|
+
List,
|
|
21
|
+
Optional,
|
|
22
|
+
Pattern,
|
|
23
|
+
Sequence,
|
|
24
|
+
Set,
|
|
25
|
+
Union,
|
|
26
|
+
cast,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
from playwright._impl._api_structures import (
|
|
30
|
+
BrowserBindResult,
|
|
31
|
+
ClientCertificate,
|
|
32
|
+
Geolocation,
|
|
33
|
+
HttpCredentials,
|
|
34
|
+
ProxySettings,
|
|
35
|
+
StorageState,
|
|
36
|
+
ViewportSize,
|
|
37
|
+
)
|
|
38
|
+
from playwright._impl._artifact import Artifact
|
|
39
|
+
from playwright._impl._browser_context import BrowserContext
|
|
40
|
+
from playwright._impl._cdp_session import CDPSession
|
|
41
|
+
from playwright._impl._connection import ChannelOwner, from_channel
|
|
42
|
+
from playwright._impl._errors import is_target_closed_error
|
|
43
|
+
from playwright._impl._helper import (
|
|
44
|
+
ColorScheme,
|
|
45
|
+
Contrast,
|
|
46
|
+
ForcedColors,
|
|
47
|
+
HarContentPolicy,
|
|
48
|
+
HarMode,
|
|
49
|
+
ReducedMotion,
|
|
50
|
+
ServiceWorkersPolicy,
|
|
51
|
+
locals_to_params,
|
|
52
|
+
make_dirs_for_file,
|
|
53
|
+
)
|
|
54
|
+
from playwright._impl._page import Page
|
|
55
|
+
|
|
56
|
+
if TYPE_CHECKING: # pragma: no cover
|
|
57
|
+
from playwright._impl._browser_type import BrowserType
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class Browser(ChannelOwner):
|
|
61
|
+
Events = SimpleNamespace(
|
|
62
|
+
Context="context",
|
|
63
|
+
Disconnected="disconnected",
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
def __init__(
|
|
67
|
+
self, parent: "BrowserType", type: str, guid: str, initializer: Dict
|
|
68
|
+
) -> None:
|
|
69
|
+
super().__init__(parent, type, guid, initializer)
|
|
70
|
+
self._browser_type: Optional["BrowserType"] = None
|
|
71
|
+
self._is_connected = True
|
|
72
|
+
self._should_close_connection_on_close = False
|
|
73
|
+
self._cr_tracing_path: Optional[str] = None
|
|
74
|
+
|
|
75
|
+
self._contexts: Set[BrowserContext] = set()
|
|
76
|
+
self._traces_dir: Optional[str] = None
|
|
77
|
+
self._channel.on(
|
|
78
|
+
"context",
|
|
79
|
+
lambda params: self._did_create_context(
|
|
80
|
+
cast(BrowserContext, from_channel(params["context"]))
|
|
81
|
+
),
|
|
82
|
+
)
|
|
83
|
+
self._channel.on("close", lambda _: self._on_close())
|
|
84
|
+
self._close_reason: Optional[str] = None
|
|
85
|
+
|
|
86
|
+
def __repr__(self) -> str:
|
|
87
|
+
return f"<Browser type={self._browser_type} version={self.version}>"
|
|
88
|
+
|
|
89
|
+
def _connect_to_browser_type(
|
|
90
|
+
self,
|
|
91
|
+
browser_type: "BrowserType",
|
|
92
|
+
traces_dir: Optional[str] = None,
|
|
93
|
+
) -> None:
|
|
94
|
+
# Note: when using connect(), `browserType` is different from `this.parent`.
|
|
95
|
+
# This is why browser type is not wired up in the constructor, and instead this separate method is called later on.
|
|
96
|
+
self._browser_type = browser_type
|
|
97
|
+
self._traces_dir = traces_dir
|
|
98
|
+
for context in self._contexts:
|
|
99
|
+
self._setup_browser_context(context)
|
|
100
|
+
|
|
101
|
+
def _did_create_context(self, context: BrowserContext) -> None:
|
|
102
|
+
context._browser = self
|
|
103
|
+
self._contexts.add(context)
|
|
104
|
+
# Note: when connecting to a browser, initial contexts arrive before `_browserType` is set,
|
|
105
|
+
# and will be configured later in `ConnectToBrowserType`.
|
|
106
|
+
if self._browser_type:
|
|
107
|
+
self._setup_browser_context(context)
|
|
108
|
+
self.emit(Browser.Events.Context, context)
|
|
109
|
+
|
|
110
|
+
def _setup_browser_context(self, context: BrowserContext) -> None:
|
|
111
|
+
context._tracing._traces_dir = self._traces_dir
|
|
112
|
+
assert self._browser_type is not None
|
|
113
|
+
self._browser_type._playwright.selectors._contexts_for_selectors.add(context)
|
|
114
|
+
|
|
115
|
+
def _on_close(self) -> None:
|
|
116
|
+
self._is_connected = False
|
|
117
|
+
self.emit(Browser.Events.Disconnected, self)
|
|
118
|
+
|
|
119
|
+
@property
|
|
120
|
+
def contexts(self) -> List[BrowserContext]:
|
|
121
|
+
return list(self._contexts)
|
|
122
|
+
|
|
123
|
+
@property
|
|
124
|
+
def browser_type(self) -> "BrowserType":
|
|
125
|
+
assert self._browser_type is not None
|
|
126
|
+
return self._browser_type
|
|
127
|
+
|
|
128
|
+
def is_connected(self) -> bool:
|
|
129
|
+
return self._is_connected
|
|
130
|
+
|
|
131
|
+
async def new_context(
|
|
132
|
+
self,
|
|
133
|
+
viewport: ViewportSize = None,
|
|
134
|
+
screen: ViewportSize = None,
|
|
135
|
+
noViewport: bool = None,
|
|
136
|
+
ignoreHTTPSErrors: bool = None,
|
|
137
|
+
javaScriptEnabled: bool = None,
|
|
138
|
+
bypassCSP: bool = None,
|
|
139
|
+
userAgent: str = None,
|
|
140
|
+
locale: str = None,
|
|
141
|
+
timezoneId: str = None,
|
|
142
|
+
geolocation: Geolocation = None,
|
|
143
|
+
permissions: Sequence[str] = None,
|
|
144
|
+
extraHTTPHeaders: Dict[str, str] = None,
|
|
145
|
+
offline: bool = None,
|
|
146
|
+
httpCredentials: HttpCredentials = None,
|
|
147
|
+
deviceScaleFactor: float = None,
|
|
148
|
+
isMobile: bool = None,
|
|
149
|
+
hasTouch: bool = None,
|
|
150
|
+
colorScheme: ColorScheme = None,
|
|
151
|
+
reducedMotion: ReducedMotion = None,
|
|
152
|
+
forcedColors: ForcedColors = None,
|
|
153
|
+
contrast: Contrast = None,
|
|
154
|
+
acceptDownloads: bool = None,
|
|
155
|
+
defaultBrowserType: str = None,
|
|
156
|
+
proxy: ProxySettings = None,
|
|
157
|
+
recordHarPath: Union[Path, str] = None,
|
|
158
|
+
recordHarOmitContent: bool = None,
|
|
159
|
+
recordVideoDir: Union[Path, str] = None,
|
|
160
|
+
recordVideoSize: ViewportSize = None,
|
|
161
|
+
storageState: Union[StorageState, str, Path] = None,
|
|
162
|
+
baseURL: str = None,
|
|
163
|
+
strictSelectors: bool = None,
|
|
164
|
+
serviceWorkers: ServiceWorkersPolicy = None,
|
|
165
|
+
recordHarUrlFilter: Union[Pattern[str], str] = None,
|
|
166
|
+
recordHarMode: HarMode = None,
|
|
167
|
+
recordHarContent: HarContentPolicy = None,
|
|
168
|
+
clientCertificates: List[ClientCertificate] = None,
|
|
169
|
+
) -> BrowserContext:
|
|
170
|
+
params = locals_to_params(locals())
|
|
171
|
+
assert self._browser_type is not None
|
|
172
|
+
await self._browser_type._prepare_browser_context_params(params)
|
|
173
|
+
|
|
174
|
+
channel = await self._channel.send("newContext", None, params)
|
|
175
|
+
context = cast(BrowserContext, from_channel(channel))
|
|
176
|
+
await context._initialize_har_from_options(
|
|
177
|
+
record_har_content=recordHarContent,
|
|
178
|
+
record_har_mode=recordHarMode,
|
|
179
|
+
record_har_omit_content=recordHarOmitContent,
|
|
180
|
+
record_har_path=recordHarPath,
|
|
181
|
+
record_har_url_filter=recordHarUrlFilter,
|
|
182
|
+
)
|
|
183
|
+
return context
|
|
184
|
+
|
|
185
|
+
async def new_page(
|
|
186
|
+
self,
|
|
187
|
+
viewport: ViewportSize = None,
|
|
188
|
+
screen: ViewportSize = None,
|
|
189
|
+
noViewport: bool = None,
|
|
190
|
+
ignoreHTTPSErrors: bool = None,
|
|
191
|
+
javaScriptEnabled: bool = None,
|
|
192
|
+
bypassCSP: bool = None,
|
|
193
|
+
userAgent: str = None,
|
|
194
|
+
locale: str = None,
|
|
195
|
+
timezoneId: str = None,
|
|
196
|
+
geolocation: Geolocation = None,
|
|
197
|
+
permissions: Sequence[str] = None,
|
|
198
|
+
extraHTTPHeaders: Dict[str, str] = None,
|
|
199
|
+
offline: bool = None,
|
|
200
|
+
httpCredentials: HttpCredentials = None,
|
|
201
|
+
deviceScaleFactor: float = None,
|
|
202
|
+
isMobile: bool = None,
|
|
203
|
+
hasTouch: bool = None,
|
|
204
|
+
colorScheme: ColorScheme = None,
|
|
205
|
+
forcedColors: ForcedColors = None,
|
|
206
|
+
contrast: Contrast = None,
|
|
207
|
+
reducedMotion: ReducedMotion = None,
|
|
208
|
+
acceptDownloads: bool = None,
|
|
209
|
+
defaultBrowserType: str = None,
|
|
210
|
+
proxy: ProxySettings = None,
|
|
211
|
+
recordHarPath: Union[Path, str] = None,
|
|
212
|
+
recordHarOmitContent: bool = None,
|
|
213
|
+
recordVideoDir: Union[Path, str] = None,
|
|
214
|
+
recordVideoSize: ViewportSize = None,
|
|
215
|
+
storageState: Union[StorageState, str, Path] = None,
|
|
216
|
+
baseURL: str = None,
|
|
217
|
+
strictSelectors: bool = None,
|
|
218
|
+
serviceWorkers: ServiceWorkersPolicy = None,
|
|
219
|
+
recordHarUrlFilter: Union[Pattern[str], str] = None,
|
|
220
|
+
recordHarMode: HarMode = None,
|
|
221
|
+
recordHarContent: HarContentPolicy = None,
|
|
222
|
+
clientCertificates: List[ClientCertificate] = None,
|
|
223
|
+
) -> Page:
|
|
224
|
+
params = locals_to_params(locals())
|
|
225
|
+
|
|
226
|
+
async def inner() -> Page:
|
|
227
|
+
context = await self.new_context(**params)
|
|
228
|
+
page = await context.new_page()
|
|
229
|
+
page._owned_context = context
|
|
230
|
+
context._owner_page = page
|
|
231
|
+
return page
|
|
232
|
+
|
|
233
|
+
return await self._connection.wrap_api_call(inner, title="Create page")
|
|
234
|
+
|
|
235
|
+
async def close(self, reason: str = None) -> None:
|
|
236
|
+
self._close_reason = reason
|
|
237
|
+
try:
|
|
238
|
+
if self._should_close_connection_on_close:
|
|
239
|
+
await self._connection.stop_async()
|
|
240
|
+
else:
|
|
241
|
+
await self._channel.send("close", None, {"reason": reason})
|
|
242
|
+
except Exception as e:
|
|
243
|
+
if not is_target_closed_error(e):
|
|
244
|
+
raise e
|
|
245
|
+
|
|
246
|
+
@property
|
|
247
|
+
def version(self) -> str:
|
|
248
|
+
return self._initializer["version"]
|
|
249
|
+
|
|
250
|
+
async def new_browser_cdp_session(self) -> CDPSession:
|
|
251
|
+
return from_channel(await self._channel.send("newBrowserCDPSession", None))
|
|
252
|
+
|
|
253
|
+
async def bind(
|
|
254
|
+
self,
|
|
255
|
+
title: str,
|
|
256
|
+
workspaceDir: str = None,
|
|
257
|
+
host: str = None,
|
|
258
|
+
port: int = None,
|
|
259
|
+
) -> BrowserBindResult:
|
|
260
|
+
return await self._channel.send_return_as_dict(
|
|
261
|
+
"startServer", None, locals_to_params(locals())
|
|
262
|
+
)
|
|
263
|
+
|
|
264
|
+
async def unbind(self) -> None:
|
|
265
|
+
await self._channel.send("stopServer", None)
|
|
266
|
+
|
|
267
|
+
async def start_tracing(
|
|
268
|
+
self,
|
|
269
|
+
page: Page = None,
|
|
270
|
+
path: Union[str, Path] = None,
|
|
271
|
+
screenshots: bool = None,
|
|
272
|
+
categories: Sequence[str] = None,
|
|
273
|
+
) -> None:
|
|
274
|
+
params = locals_to_params(locals())
|
|
275
|
+
if page:
|
|
276
|
+
params["page"] = page._channel
|
|
277
|
+
if path:
|
|
278
|
+
self._cr_tracing_path = str(path)
|
|
279
|
+
params["path"] = str(path)
|
|
280
|
+
await self._channel.send("startTracing", None, params)
|
|
281
|
+
|
|
282
|
+
async def stop_tracing(self) -> bytes:
|
|
283
|
+
artifact = cast(
|
|
284
|
+
Artifact, from_channel(await self._channel.send("stopTracing", None))
|
|
285
|
+
)
|
|
286
|
+
buffer = await artifact.read_info_buffer()
|
|
287
|
+
await artifact.delete()
|
|
288
|
+
if self._cr_tracing_path:
|
|
289
|
+
make_dirs_for_file(self._cr_tracing_path)
|
|
290
|
+
with open(self._cr_tracing_path, "wb") as f:
|
|
291
|
+
f.write(buffer)
|
|
292
|
+
self._cr_tracing_path = None
|
|
293
|
+
return buffer
|