pure-patchright 1.62.3__py3-none-any.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.
Files changed (142) hide show
  1. patchright/__init__.py +5 -0
  2. patchright/__main__.py +18 -0
  3. patchright/_impl/__init__.py +0 -0
  4. patchright/_impl/__pyinstaller/__init__.py +20 -0
  5. patchright/_impl/__pyinstaller/hook-playwright.async_api.py +3 -0
  6. patchright/_impl/__pyinstaller/hook-playwright.sync_api.py +3 -0
  7. patchright/_impl/_api_structures.py +343 -0
  8. patchright/_impl/_artifact.py +46 -0
  9. patchright/_impl/_assertions.py +1014 -0
  10. patchright/_impl/_async_base.py +88 -0
  11. patchright/_impl/_browser.py +267 -0
  12. patchright/_impl/_browser_context.py +759 -0
  13. patchright/_impl/_browser_type.py +336 -0
  14. patchright/_impl/_cdp_session.py +25 -0
  15. patchright/_impl/_clock.py +62 -0
  16. patchright/_impl/_connection.py +686 -0
  17. patchright/_impl/_console_message.py +83 -0
  18. patchright/_impl/_credentials.py +38 -0
  19. patchright/_impl/_debugger.py +37 -0
  20. patchright/_impl/_dialog.py +45 -0
  21. patchright/_impl/_disposable.py +71 -0
  22. patchright/_impl/_download.py +49 -0
  23. patchright/_impl/_driver.py +24 -0
  24. patchright/_impl/_element_handle.py +446 -0
  25. patchright/_impl/_errors.py +46 -0
  26. patchright/_impl/_event_context_manager.py +19 -0
  27. patchright/_impl/_fetch.py +592 -0
  28. patchright/_impl/_file_chooser.py +42 -0
  29. patchright/_impl/_form_data.py +19 -0
  30. patchright/_impl/_frame.py +959 -0
  31. patchright/_impl/_glob.py +47 -0
  32. patchright/_impl/_greenlets.py +35 -0
  33. patchright/_impl/_har_router.py +98 -0
  34. patchright/_impl/_helper.py +551 -0
  35. patchright/_impl/_impl_to_api_mapping.py +141 -0
  36. patchright/_impl/_input.py +85 -0
  37. patchright/_impl/_js_handle.py +297 -0
  38. patchright/_impl/_json_pipe.py +55 -0
  39. patchright/_impl/_local_utils.py +73 -0
  40. patchright/_impl/_locator.py +894 -0
  41. patchright/_impl/_map.py +18 -0
  42. patchright/_impl/_network.py +953 -0
  43. patchright/_impl/_object_factory.py +93 -0
  44. patchright/_impl/_page.py +1601 -0
  45. patchright/_impl/_path_utils.py +13 -0
  46. patchright/_impl/_playwright.py +43 -0
  47. patchright/_impl/_screencast.py +149 -0
  48. patchright/_impl/_selectors.py +48 -0
  49. patchright/_impl/_set_input_files_helpers.py +134 -0
  50. patchright/_impl/_str_utils.py +59 -0
  51. patchright/_impl/_stream.py +31 -0
  52. patchright/_impl/_sync_base.py +130 -0
  53. patchright/_impl/_tracing.py +243 -0
  54. patchright/_impl/_transport.py +151 -0
  55. patchright/_impl/_video.py +41 -0
  56. patchright/_impl/_waiter.py +168 -0
  57. patchright/_impl/_web_error.py +33 -0
  58. patchright/_impl/_web_storage.py +41 -0
  59. patchright/_impl/_writable_stream.py +26 -0
  60. patchright/_repo_version.py +1 -0
  61. patchright/async_api/__init__.py +234 -0
  62. patchright/async_api/_context_manager.py +38 -0
  63. patchright/async_api/_generated.py +23396 -0
  64. patchright/driver/README.md +1 -0
  65. patchright/driver/package/README.md +3 -0
  66. patchright/driver/package/ThirdPartyNotices.txt +13 -0
  67. patchright/driver/package/bin/install_media_pack.ps1 +5 -0
  68. patchright/driver/package/bin/install_webkit_wsl.ps1 +33 -0
  69. patchright/driver/package/bin/reinstall_chrome_beta_linux.sh +42 -0
  70. patchright/driver/package/bin/reinstall_chrome_beta_mac.sh +13 -0
  71. patchright/driver/package/bin/reinstall_chrome_beta_win.ps1 +24 -0
  72. patchright/driver/package/bin/reinstall_chrome_stable_linux.sh +42 -0
  73. patchright/driver/package/bin/reinstall_chrome_stable_mac.sh +12 -0
  74. patchright/driver/package/bin/reinstall_chrome_stable_win.ps1 +24 -0
  75. patchright/driver/package/bin/reinstall_msedge_beta_linux.sh +48 -0
  76. patchright/driver/package/bin/reinstall_msedge_beta_mac.sh +11 -0
  77. patchright/driver/package/bin/reinstall_msedge_beta_win.ps1 +23 -0
  78. patchright/driver/package/bin/reinstall_msedge_dev_linux.sh +48 -0
  79. patchright/driver/package/bin/reinstall_msedge_dev_mac.sh +11 -0
  80. patchright/driver/package/bin/reinstall_msedge_dev_win.ps1 +23 -0
  81. patchright/driver/package/bin/reinstall_msedge_stable_linux.sh +48 -0
  82. patchright/driver/package/bin/reinstall_msedge_stable_mac.sh +11 -0
  83. patchright/driver/package/bin/reinstall_msedge_stable_win.ps1 +24 -0
  84. patchright/driver/package/browsers.json +75 -0
  85. patchright/driver/package/cli.js +21 -0
  86. patchright/driver/package/index.js +17 -0
  87. patchright/driver/package/index.mjs +28 -0
  88. patchright/driver/package/lib/bootstrap.js +88 -0
  89. patchright/driver/package/lib/coreBundle.js +77498 -0
  90. patchright/driver/package/lib/entry/cliDaemon.js +5 -0
  91. patchright/driver/package/lib/entry/dashboardApp.js +3 -0
  92. patchright/driver/package/lib/entry/mcp.js +10 -0
  93. patchright/driver/package/lib/entry/oopBrowserDownload.js +3 -0
  94. patchright/driver/package/lib/package.js +50 -0
  95. patchright/driver/package/lib/server/chromium/appIcon.png +0 -0
  96. patchright/driver/package/lib/server/electron/loader.js +107 -0
  97. patchright/driver/package/lib/serverRegistry.js +7347 -0
  98. patchright/driver/package/lib/serverRegistry.js.LICENSE +354 -0
  99. patchright/driver/package/lib/tools/cli-client/channelSessions.js +141 -0
  100. patchright/driver/package/lib/tools/cli-client/cli.js +6 -0
  101. patchright/driver/package/lib/tools/cli-client/help.json +708 -0
  102. patchright/driver/package/lib/tools/cli-client/minimist.js +128 -0
  103. patchright/driver/package/lib/tools/cli-client/output.js +343 -0
  104. patchright/driver/package/lib/tools/cli-client/program.js +404 -0
  105. patchright/driver/package/lib/tools/cli-client/registry.js +176 -0
  106. patchright/driver/package/lib/tools/cli-client/session.js +258 -0
  107. patchright/driver/package/lib/tools/dashboard/appIcon.png +0 -0
  108. patchright/driver/package/lib/tools/skills/playwright-cli/SKILL.md +420 -0
  109. patchright/driver/package/lib/tools/skills/playwright-cli/references/element-attributes.md +23 -0
  110. patchright/driver/package/lib/tools/skills/playwright-cli/references/playwright-tests.md +39 -0
  111. patchright/driver/package/lib/tools/skills/playwright-cli/references/request-mocking.md +87 -0
  112. patchright/driver/package/lib/tools/skills/playwright-cli/references/running-code.md +241 -0
  113. patchright/driver/package/lib/tools/skills/playwright-cli/references/session-management.md +225 -0
  114. patchright/driver/package/lib/tools/skills/playwright-cli/references/storage-state.md +275 -0
  115. patchright/driver/package/lib/tools/skills/playwright-cli/references/test-generation.md +433 -0
  116. patchright/driver/package/lib/tools/skills/playwright-cli/references/tracing.md +139 -0
  117. patchright/driver/package/lib/tools/skills/playwright-cli/references/video-recording.md +143 -0
  118. patchright/driver/package/lib/tools/skills/playwright-component-testing/SKILL.md +143 -0
  119. patchright/driver/package/lib/tools/skills/playwright-component-testing/references/gallery-spec.md +144 -0
  120. patchright/driver/package/lib/tools/skills/playwright-component-testing/references/migration.md +85 -0
  121. patchright/driver/package/lib/tools/skills/playwright-component-testing/references/react.md +67 -0
  122. patchright/driver/package/lib/tools/skills/playwright-component-testing/references/vue.md +75 -0
  123. patchright/driver/package/lib/tools/skills/playwright-trace/SKILL.md +171 -0
  124. patchright/driver/package/lib/tools/utils/extension.js +101 -0
  125. patchright/driver/package/lib/tools/utils/socketConnection.js +108 -0
  126. patchright/driver/package/lib/utilsBundle.js +90764 -0
  127. patchright/driver/package/lib/utilsBundle.js.LICENSE +2179 -0
  128. patchright/driver/package/lib/webp_codec.LICENSE +173 -0
  129. patchright/driver/package/lib/webp_codec.wasm +0 -0
  130. patchright/driver/package/lib/xdg-open +1267 -0
  131. patchright/driver/package/package.json +34 -0
  132. patchright/py.typed +0 -0
  133. patchright/sync_api/__init__.py +234 -0
  134. patchright/sync_api/_context_manager.py +73 -0
  135. patchright/sync_api/_generated.py +23590 -0
  136. pure_patchright-1.62.3.dist-info/LICENSE +201 -0
  137. pure_patchright-1.62.3.dist-info/METADATA +96 -0
  138. pure_patchright-1.62.3.dist-info/RECORD +142 -0
  139. pure_patchright-1.62.3.dist-info/WHEEL +4 -0
  140. pure_patchright-1.62.3.dist-info/entry_points.txt +5 -0
  141. pure_patchright-1.62.3.dist-info/licenses/LICENSE +202 -0
  142. pure_patchright-1.62.3.dist-info/top_level.txt +1 -0
@@ -0,0 +1,83 @@
1
+ from asyncio import AbstractEventLoop
2
+ from typing import TYPE_CHECKING, Any, Dict, List, Literal, Optional, Union
3
+ from patchright._impl._api_structures import SourceLocation
4
+ from patchright._impl._connection import from_channel, from_nullable_channel
5
+ from patchright._impl._js_handle import JSHandle
6
+
7
+ if TYPE_CHECKING:
8
+ from patchright._impl._page import Page
9
+ from patchright._impl._worker import Worker
10
+
11
+
12
+ class ConsoleMessage:
13
+ def __init__(
14
+ self, event: Dict, loop: AbstractEventLoop, dispatcher_fiber: Any
15
+ ) -> None:
16
+ self._event = event
17
+ self._loop = loop
18
+ self._dispatcher_fiber = dispatcher_fiber
19
+ self._page: Optional["Page"] = from_nullable_channel(event.get("page"))
20
+ self._worker: Optional["Worker"] = from_nullable_channel(event.get("worker"))
21
+
22
+ def __repr__(self) -> str:
23
+ return f"<ConsoleMessage type={self.type} text={self.text}>"
24
+
25
+ def __str__(self) -> str:
26
+ return self.text
27
+
28
+ @property
29
+ def type(
30
+ self,
31
+ ) -> Union[
32
+ Literal["assert"],
33
+ Literal["clear"],
34
+ Literal["count"],
35
+ Literal["debug"],
36
+ Literal["dir"],
37
+ Literal["dirxml"],
38
+ Literal["endGroup"],
39
+ Literal["error"],
40
+ Literal["info"],
41
+ Literal["log"],
42
+ Literal["profile"],
43
+ Literal["profileEnd"],
44
+ Literal["startGroup"],
45
+ Literal["startGroupCollapsed"],
46
+ Literal["table"],
47
+ Literal["time"],
48
+ Literal["timeEnd"],
49
+ Literal["trace"],
50
+ Literal["warning"],
51
+ ]:
52
+ return self._event["type"]
53
+
54
+ @property
55
+ def text(self) -> str:
56
+ return self._event["text"]
57
+
58
+ @property
59
+ def args(self) -> List[JSHandle]:
60
+ return list(map(from_channel, self._event["args"]))
61
+
62
+ @property
63
+ def location(self) -> SourceLocation:
64
+ loc = self._event["location"]
65
+ return {
66
+ "url": loc["url"],
67
+ "line": loc["lineNumber"],
68
+ "column": loc["columnNumber"],
69
+ "lineNumber": loc["lineNumber"],
70
+ "columnNumber": loc["columnNumber"],
71
+ }
72
+
73
+ @property
74
+ def timestamp(self) -> float:
75
+ return self._event["timestamp"]
76
+
77
+ @property
78
+ def page(self) -> Optional["Page"]:
79
+ return self._page
80
+
81
+ @property
82
+ def worker(self) -> Optional["Worker"]:
83
+ return self._worker
@@ -0,0 +1,38 @@
1
+ from typing import TYPE_CHECKING, List
2
+ from patchright._impl._api_structures import VirtualCredential
3
+ from patchright._impl._helper import locals_to_params
4
+
5
+ if TYPE_CHECKING:
6
+ from patchright._impl._browser_context import BrowserContext
7
+
8
+
9
+ class Credentials:
10
+ def __init__(self, browser_context: "BrowserContext") -> None:
11
+ self._browser_context = browser_context
12
+ self._loop = browser_context._loop
13
+ self._dispatcher_fiber = browser_context._dispatcher_fiber
14
+
15
+ async def install(self) -> None:
16
+ await self._browser_context._channel.send("credentialsInstall", None)
17
+
18
+ async def create(
19
+ self,
20
+ rpId: str,
21
+ id: str = None,
22
+ userHandle: str = None,
23
+ privateKey: str = None,
24
+ publicKey: str = None,
25
+ ) -> VirtualCredential:
26
+ result = await self._browser_context._channel.send_return_as_dict(
27
+ "credentialsCreate", None, locals_to_params(locals())
28
+ )
29
+ return (result or {})["credential"]
30
+
31
+ async def delete(self, id: str) -> None:
32
+ await self._browser_context._channel.send("credentialsDelete", None, {"id": id})
33
+
34
+ async def get(self, rpId: str = None, id: str = None) -> List[VirtualCredential]:
35
+ result = await self._browser_context._channel.send_return_as_dict(
36
+ "credentialsGet", None, locals_to_params(locals())
37
+ )
38
+ return (result or {}).get("credentials", [])
@@ -0,0 +1,37 @@
1
+ from types import SimpleNamespace
2
+ from typing import Any, Dict, Optional
3
+ from patchright._impl._api_structures import DebuggerLocation, DebuggerPausedDetails
4
+ from patchright._impl._connection import ChannelOwner
5
+
6
+
7
+ class Debugger(ChannelOwner):
8
+ Events = SimpleNamespace(PausedStateChanged="pausedstatechanged")
9
+
10
+ def __init__(
11
+ self, parent: ChannelOwner, type: str, guid: str, initializer: Dict
12
+ ) -> None:
13
+ super().__init__(parent, type, guid, initializer)
14
+ self._paused_details: Optional[DebuggerPausedDetails] = None
15
+ self._channel.on(
16
+ "pausedStateChanged", lambda params: self._on_paused_state_changed(params)
17
+ )
18
+
19
+ def _on_paused_state_changed(self, params: Dict[str, Any]) -> None:
20
+ self._paused_details = params.get("pausedDetails")
21
+ self.emit(Debugger.Events.PausedStateChanged)
22
+
23
+ async def request_pause(self) -> None:
24
+ await self._channel.send("requestPause", None)
25
+
26
+ async def resume(self) -> None:
27
+ await self._channel.send("resume", None)
28
+
29
+ async def next(self) -> None:
30
+ await self._channel.send("next", None)
31
+
32
+ async def run_to(self, location: DebuggerLocation) -> None:
33
+ await self._channel.send("runTo", None, {"location": location})
34
+
35
+ @property
36
+ def paused_details(self) -> Optional[DebuggerPausedDetails]:
37
+ return self._paused_details
@@ -0,0 +1,45 @@
1
+ from typing import TYPE_CHECKING, Dict, Optional
2
+ from patchright._impl._connection import ChannelOwner, from_nullable_channel
3
+ from patchright._impl._errors import is_target_closed_error
4
+ from patchright._impl._helper import locals_to_params
5
+
6
+ if TYPE_CHECKING:
7
+ from patchright._impl._page import Page
8
+
9
+
10
+ class Dialog(ChannelOwner):
11
+ def __init__(
12
+ self, parent: ChannelOwner, type: str, guid: str, initializer: Dict
13
+ ) -> None:
14
+ super().__init__(parent, type, guid, initializer)
15
+ self._page: Optional["Page"] = from_nullable_channel(initializer.get("page"))
16
+
17
+ def __repr__(self) -> str:
18
+ return f"<Dialog type={self.type} message={self.message} default_value={self.default_value}>"
19
+
20
+ @property
21
+ def type(self) -> str:
22
+ return self._initializer["type"]
23
+
24
+ @property
25
+ def message(self) -> str:
26
+ return self._initializer["message"]
27
+
28
+ @property
29
+ def default_value(self) -> str:
30
+ return self._initializer["defaultValue"]
31
+
32
+ @property
33
+ def page(self) -> Optional["Page"]:
34
+ return self._page
35
+
36
+ async def accept(self, promptText: str = None) -> None:
37
+ await self._channel.send("accept", None, locals_to_params(locals()))
38
+
39
+ async def dismiss(self) -> None:
40
+ try:
41
+ await self._channel.send("dismiss", None)
42
+ except Exception as e:
43
+ if is_target_closed_error(e):
44
+ return
45
+ raise
@@ -0,0 +1,71 @@
1
+ import asyncio
2
+ import traceback
3
+ from typing import Awaitable, Callable, Dict
4
+ import greenlet
5
+ from patchright._impl._connection import ChannelOwner, _capture_stack_trace
6
+ from patchright._impl._errors import Error, is_target_closed_error
7
+
8
+
9
+ class Disposable(ChannelOwner):
10
+ def __init__(
11
+ self, parent: ChannelOwner, type: str, guid: str, initializer: Dict
12
+ ) -> None:
13
+ super().__init__(parent, type, guid, initializer)
14
+
15
+ async def dispose(self) -> None:
16
+ try:
17
+ await self._channel.send("dispose", None)
18
+ except Exception as e:
19
+ if not is_target_closed_error(e):
20
+ raise e
21
+
22
+ async def close(self) -> None:
23
+ await self.dispose()
24
+
25
+ def __repr__(self) -> str:
26
+ return "<Disposable>"
27
+
28
+
29
+ class DisposableStub:
30
+ def __init__(
31
+ self, dispose_fn: Callable[[], Awaitable[None]], parent: ChannelOwner
32
+ ) -> None:
33
+ self._dispose_fn = dispose_fn
34
+ self._loop = parent._loop
35
+ self._dispatcher_fiber = parent._dispatcher_fiber
36
+
37
+ async def dispose(self) -> None:
38
+ await self._dispose_fn()
39
+
40
+ async def __aenter__(self) -> "DisposableStub":
41
+ return self
42
+
43
+ async def __aexit__(self, *args: object) -> None:
44
+ await self.dispose()
45
+
46
+ def __enter__(self) -> "DisposableStub":
47
+ return self
48
+
49
+ def __exit__(self, *args: object) -> None:
50
+ self._sync(self.dispose())
51
+
52
+ def _sync(self, coro: object) -> object:
53
+ __tracebackhide__ = True
54
+ if self._loop.is_closed():
55
+ coro.close()
56
+ raise Error("Event loop is closed! Is Playwright already stopped?")
57
+ g_self = greenlet.getcurrent()
58
+ task = self._loop.create_task(coro)
59
+ setattr(task, "__pw_stack__", _capture_stack_trace())
60
+ setattr(task, "__pw_stack_trace__", traceback.extract_stack(limit=10))
61
+ task.add_done_callback(lambda _: g_self.switch())
62
+ while not task.done():
63
+ self._dispatcher_fiber.switch()
64
+ asyncio._set_running_loop(self._loop)
65
+ return task.result()
66
+
67
+ async def close(self) -> None:
68
+ await self.dispose()
69
+
70
+ def __repr__(self) -> str:
71
+ return "<Disposable>"
@@ -0,0 +1,49 @@
1
+ import pathlib
2
+ from pathlib import Path
3
+ from typing import TYPE_CHECKING, Optional, Union
4
+ from patchright._impl._artifact import Artifact
5
+
6
+ if TYPE_CHECKING:
7
+ from patchright._impl._page import Page
8
+
9
+
10
+ class Download:
11
+ def __init__(
12
+ self, page: "Page", url: str, suggested_filename: str, artifact: Artifact
13
+ ) -> None:
14
+ self._page = page
15
+ self._loop = page._loop
16
+ self._dispatcher_fiber = page._dispatcher_fiber
17
+ self._url = url
18
+ self._suggested_filename = suggested_filename
19
+ self._artifact = artifact
20
+
21
+ def __repr__(self) -> str:
22
+ return f"<Download url={self.url!r} suggested_filename={self.suggested_filename!r}>"
23
+
24
+ @property
25
+ def page(self) -> "Page":
26
+ return self._page
27
+
28
+ @property
29
+ def url(self) -> str:
30
+ return self._url
31
+
32
+ @property
33
+ def suggested_filename(self) -> str:
34
+ return self._suggested_filename
35
+
36
+ async def delete(self) -> None:
37
+ await self._artifact.delete()
38
+
39
+ async def failure(self) -> Optional[str]:
40
+ return await self._artifact.failure()
41
+
42
+ async def path(self) -> pathlib.Path:
43
+ return await self._artifact.path_after_finished()
44
+
45
+ async def save_as(self, path: Union[str, Path]) -> None:
46
+ await self._artifact.save_as(path)
47
+
48
+ async def cancel(self) -> None:
49
+ return await self._artifact.cancel()
@@ -0,0 +1,24 @@
1
+ import inspect
2
+ import os
3
+ import sys
4
+ from pathlib import Path
5
+ from typing import Tuple
6
+ import patchright
7
+ from patchright._repo_version import version
8
+ import shutil
9
+ from patchright._impl._errors import Error
10
+
11
+ def compute_driver_executable() -> Tuple[str, str]:
12
+ driver_path = Path(inspect.getfile(patchright)).parent / 'driver'
13
+ cli_path = str(driver_path / 'package' / 'cli.js')
14
+ node_path = os.getenv('PLAYWRIGHT_NODEJS_PATH') or shutil.which('node') or shutil.which('nodejs')
15
+ if not node_path:
16
+ raise Error('Node.js executable not found. Install Node.js (>=18) on PATH or set PLAYWRIGHT_NODEJS_PATH pointing to the Node.js binary.')
17
+ return (node_path, cli_path)
18
+
19
+ def get_driver_env() -> dict:
20
+ env = os.environ.copy()
21
+ env['PW_LANG_NAME'] = 'python'
22
+ env['PW_LANG_NAME_VERSION'] = f'{sys.version_info.major}.{sys.version_info.minor}'
23
+ env['PW_CLI_DISPLAY_VERSION'] = version
24
+ return env