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,88 @@
1
+ import asyncio
2
+ from contextlib import AbstractAsyncContextManager
3
+ from types import TracebackType
4
+ from typing import Any, Callable, Generic, Optional, Type, TypeVar, Union
5
+ from patchright._impl._impl_to_api_mapping import ImplToApiMapping, ImplWrapper
6
+
7
+ mapping = ImplToApiMapping()
8
+ T = TypeVar("T")
9
+ Self = TypeVar("Self", bound="AsyncContextManager")
10
+
11
+
12
+ class AsyncEventInfo(Generic[T]):
13
+ def __init__(self, future: "asyncio.Future[T]") -> None:
14
+ self._future = future
15
+
16
+ @property
17
+ async def value(self) -> T:
18
+ return mapping.from_maybe_impl(await self._future)
19
+
20
+ def _cancel(self) -> None:
21
+ self._future.cancel()
22
+
23
+ def is_done(self) -> bool:
24
+ return self._future.done()
25
+
26
+
27
+ class AsyncEventContextManager(Generic[T], AbstractAsyncContextManager):
28
+ def __init__(self, future: "asyncio.Future[T]") -> None:
29
+ self._event = AsyncEventInfo[T](future)
30
+
31
+ async def __aenter__(self) -> AsyncEventInfo[T]:
32
+ return self._event
33
+
34
+ async def __aexit__(
35
+ self,
36
+ exc_type: Optional[Type[BaseException]],
37
+ exc_val: Optional[BaseException],
38
+ exc_tb: Optional[TracebackType],
39
+ ) -> None:
40
+ if exc_val:
41
+ self._event._cancel()
42
+ else:
43
+ await self._event.value
44
+
45
+
46
+ class AsyncBase(ImplWrapper):
47
+ def __init__(self, impl_obj: Any) -> None:
48
+ super().__init__(impl_obj)
49
+ self._loop = impl_obj._loop
50
+
51
+ def __str__(self) -> str:
52
+ return self._impl_obj.__str__()
53
+
54
+ def _wrap_handler(
55
+ self, handler: Union[Callable[..., Any], Any]
56
+ ) -> Callable[..., None]:
57
+ if callable(handler):
58
+ return mapping.wrap_handler(handler)
59
+ return handler
60
+
61
+ def on(self, event: Any, f: Any) -> None:
62
+ """Registers the function ``f`` to the event name ``event``."""
63
+ self._impl_obj.on(event, self._wrap_handler(f))
64
+
65
+ def once(self, event: Any, f: Any) -> None:
66
+ """The same as ``self.on``, except that the listener is automatically
67
+ removed after being called.
68
+ """
69
+ self._impl_obj.once(event, self._wrap_handler(f))
70
+
71
+ def remove_listener(self, event: Any, f: Any) -> None:
72
+ """Removes the function ``f`` from ``event``."""
73
+ self._impl_obj.remove_listener(event, self._wrap_handler(f))
74
+
75
+
76
+ class AsyncContextManager(AsyncBase):
77
+ async def __aenter__(self: Self) -> Self:
78
+ return self
79
+
80
+ async def __aexit__(
81
+ self,
82
+ exc_type: Optional[Type[BaseException]],
83
+ exc_val: Optional[BaseException],
84
+ traceback: Optional[TracebackType],
85
+ ) -> None:
86
+ await self.close()
87
+
88
+ async def close(self) -> None: ...
@@ -0,0 +1,267 @@
1
+ from pathlib import Path
2
+ from types import SimpleNamespace
3
+ from typing import (
4
+ TYPE_CHECKING,
5
+ Dict,
6
+ List,
7
+ Optional,
8
+ Pattern,
9
+ Sequence,
10
+ Set,
11
+ Union,
12
+ cast,
13
+ )
14
+ from patchright._impl._api_structures import (
15
+ BrowserBindResult,
16
+ ClientCertificate,
17
+ Geolocation,
18
+ HttpCredentials,
19
+ ProxySettings,
20
+ StorageState,
21
+ ViewportSize,
22
+ )
23
+ from patchright._impl._artifact import Artifact
24
+ from patchright._impl._browser_context import BrowserContext
25
+ from patchright._impl._cdp_session import CDPSession
26
+ from patchright._impl._connection import ChannelOwner, from_channel
27
+ from patchright._impl._errors import is_target_closed_error
28
+ from patchright._impl._helper import (
29
+ ColorScheme,
30
+ Contrast,
31
+ ForcedColors,
32
+ HarContentPolicy,
33
+ HarMode,
34
+ ReducedMotion,
35
+ ServiceWorkersPolicy,
36
+ locals_to_params,
37
+ make_dirs_for_file,
38
+ )
39
+ from patchright._impl._page import Page
40
+
41
+ if TYPE_CHECKING:
42
+ from patchright._impl._browser_type import BrowserType
43
+
44
+
45
+ class Browser(ChannelOwner):
46
+ Events = SimpleNamespace(Context="context", Disconnected="disconnected")
47
+
48
+ def __init__(
49
+ self, parent: "BrowserType", type: str, guid: str, initializer: Dict
50
+ ) -> None:
51
+ super().__init__(parent, type, guid, initializer)
52
+ self._browser_type: Optional["BrowserType"] = None
53
+ self._is_connected = True
54
+ self._should_close_connection_on_close = False
55
+ self._cr_tracing_path: Optional[str] = None
56
+ self._contexts: Set[BrowserContext] = set()
57
+ self._traces_dir: Optional[str] = None
58
+ self._channel.on(
59
+ "context",
60
+ lambda params: self._did_create_context(
61
+ cast(BrowserContext, from_channel(params["context"]))
62
+ ),
63
+ )
64
+ self._channel.on("close", lambda _: self._on_close())
65
+ self._close_reason: Optional[str] = None
66
+
67
+ def __repr__(self) -> str:
68
+ return f"<Browser type={self._browser_type} version={self.version}>"
69
+
70
+ def _connect_to_browser_type(
71
+ self, browser_type: "BrowserType", traces_dir: Optional[str] = None
72
+ ) -> None:
73
+ self._browser_type = browser_type
74
+ self._traces_dir = traces_dir
75
+ for context in self._contexts:
76
+ self._setup_browser_context(context)
77
+
78
+ def _did_create_context(self, context: BrowserContext) -> None:
79
+ context._browser = self
80
+ self._contexts.add(context)
81
+ if self._browser_type:
82
+ self._setup_browser_context(context)
83
+ self.emit(Browser.Events.Context, context)
84
+
85
+ def _setup_browser_context(self, context: BrowserContext) -> None:
86
+ context._tracing._traces_dir = self._traces_dir
87
+ assert self._browser_type is not None
88
+ self._browser_type._playwright.selectors._contexts_for_selectors.add(context)
89
+
90
+ def _on_close(self) -> None:
91
+ self._is_connected = False
92
+ self.emit(Browser.Events.Disconnected, self)
93
+
94
+ @property
95
+ def contexts(self) -> List[BrowserContext]:
96
+ return list(self._contexts)
97
+
98
+ @property
99
+ def browser_type(self) -> "BrowserType":
100
+ assert self._browser_type is not None
101
+ return self._browser_type
102
+
103
+ def is_connected(self) -> bool:
104
+ return self._is_connected
105
+
106
+ async def new_context(
107
+ self,
108
+ viewport: ViewportSize = None,
109
+ screen: ViewportSize = None,
110
+ noViewport: bool = None,
111
+ ignoreHTTPSErrors: bool = None,
112
+ javaScriptEnabled: bool = None,
113
+ bypassCSP: bool = None,
114
+ userAgent: str = None,
115
+ locale: str = None,
116
+ timezoneId: str = None,
117
+ geolocation: Geolocation = None,
118
+ permissions: Sequence[str] = None,
119
+ extraHTTPHeaders: Dict[str, str] = None,
120
+ offline: bool = None,
121
+ httpCredentials: HttpCredentials = None,
122
+ deviceScaleFactor: float = None,
123
+ isMobile: bool = None,
124
+ hasTouch: bool = None,
125
+ colorScheme: ColorScheme = None,
126
+ reducedMotion: ReducedMotion = None,
127
+ forcedColors: ForcedColors = None,
128
+ contrast: Contrast = None,
129
+ acceptDownloads: bool = None,
130
+ defaultBrowserType: str = None,
131
+ proxy: ProxySettings = None,
132
+ recordHarPath: Union[Path, str] = None,
133
+ recordHarOmitContent: bool = None,
134
+ recordVideoDir: Union[Path, str] = None,
135
+ recordVideoSize: ViewportSize = None,
136
+ storageState: Union[StorageState, str, Path] = None,
137
+ baseURL: str = None,
138
+ strictSelectors: bool = None,
139
+ serviceWorkers: ServiceWorkersPolicy = None,
140
+ recordHarUrlFilter: Union[Pattern[str], str] = None,
141
+ recordHarMode: HarMode = None,
142
+ recordHarContent: HarContentPolicy = None,
143
+ clientCertificates: List[ClientCertificate] = None,
144
+ *,
145
+ focusControl: Optional[bool] = None,
146
+ ) -> BrowserContext:
147
+ params = locals_to_params(locals())
148
+ assert self._browser_type is not None
149
+ await self._browser_type._prepare_browser_context_params(params)
150
+ channel = await self._channel.send("newContext", None, params)
151
+ context = cast(BrowserContext, from_channel(channel))
152
+ await context._initialize_har_from_options(
153
+ record_har_content=recordHarContent,
154
+ record_har_mode=recordHarMode,
155
+ record_har_omit_content=recordHarOmitContent,
156
+ record_har_path=recordHarPath,
157
+ record_har_url_filter=recordHarUrlFilter,
158
+ )
159
+ return context
160
+
161
+ async def new_page(
162
+ self,
163
+ viewport: ViewportSize = None,
164
+ screen: ViewportSize = None,
165
+ noViewport: bool = None,
166
+ ignoreHTTPSErrors: bool = None,
167
+ javaScriptEnabled: bool = None,
168
+ bypassCSP: bool = None,
169
+ userAgent: str = None,
170
+ locale: str = None,
171
+ timezoneId: str = None,
172
+ geolocation: Geolocation = None,
173
+ permissions: Sequence[str] = None,
174
+ extraHTTPHeaders: Dict[str, str] = None,
175
+ offline: bool = None,
176
+ httpCredentials: HttpCredentials = None,
177
+ deviceScaleFactor: float = None,
178
+ isMobile: bool = None,
179
+ hasTouch: bool = None,
180
+ colorScheme: ColorScheme = None,
181
+ forcedColors: ForcedColors = None,
182
+ contrast: Contrast = None,
183
+ reducedMotion: ReducedMotion = None,
184
+ acceptDownloads: bool = None,
185
+ defaultBrowserType: str = None,
186
+ proxy: ProxySettings = None,
187
+ recordHarPath: Union[Path, str] = None,
188
+ recordHarOmitContent: bool = None,
189
+ recordVideoDir: Union[Path, str] = None,
190
+ recordVideoSize: ViewportSize = None,
191
+ storageState: Union[StorageState, str, Path] = None,
192
+ baseURL: str = None,
193
+ strictSelectors: bool = None,
194
+ serviceWorkers: ServiceWorkersPolicy = None,
195
+ recordHarUrlFilter: Union[Pattern[str], str] = None,
196
+ recordHarMode: HarMode = None,
197
+ recordHarContent: HarContentPolicy = None,
198
+ clientCertificates: List[ClientCertificate] = None,
199
+ *,
200
+ focusControl: Optional[bool] = None,
201
+ ) -> Page:
202
+ params = locals_to_params(locals())
203
+
204
+ async def inner() -> Page:
205
+ context = await self.new_context(**params)
206
+ page = await context.new_page()
207
+ page._owned_context = context
208
+ context._owner_page = page
209
+ return page
210
+
211
+ return await self._connection.wrap_api_call(inner, title="Create page")
212
+
213
+ async def close(self, reason: str = None) -> None:
214
+ self._close_reason = reason
215
+ try:
216
+ if self._should_close_connection_on_close:
217
+ await self._connection.stop_async()
218
+ else:
219
+ await self._channel.send("close", None, {"reason": reason})
220
+ except Exception as e:
221
+ if not is_target_closed_error(e):
222
+ raise e
223
+
224
+ @property
225
+ def version(self) -> str:
226
+ return self._initializer["version"]
227
+
228
+ async def new_browser_cdp_session(self) -> CDPSession:
229
+ return from_channel(await self._channel.send("newBrowserCDPSession", None))
230
+
231
+ async def bind(
232
+ self, title: str, workspaceDir: str = None, host: str = None, port: int = None
233
+ ) -> BrowserBindResult:
234
+ return await self._channel.send_return_as_dict(
235
+ "startServer", None, locals_to_params(locals())
236
+ )
237
+
238
+ async def unbind(self) -> None:
239
+ await self._channel.send("stopServer", None)
240
+
241
+ async def start_tracing(
242
+ self,
243
+ page: Page = None,
244
+ path: Union[str, Path] = None,
245
+ screenshots: bool = None,
246
+ categories: Sequence[str] = None,
247
+ ) -> None:
248
+ params = locals_to_params(locals())
249
+ if page:
250
+ params["page"] = page._channel
251
+ if path:
252
+ self._cr_tracing_path = str(path)
253
+ params["path"] = str(path)
254
+ await self._channel.send("startTracing", None, params)
255
+
256
+ async def stop_tracing(self) -> bytes:
257
+ artifact = cast(
258
+ Artifact, from_channel(await self._channel.send("stopTracing", None))
259
+ )
260
+ buffer = await artifact.read_info_buffer()
261
+ await artifact.delete()
262
+ if self._cr_tracing_path:
263
+ make_dirs_for_file(self._cr_tracing_path)
264
+ with open(self._cr_tracing_path, "wb") as f:
265
+ f.write(buffer)
266
+ self._cr_tracing_path = None
267
+ return buffer