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,446 @@
1
+ import base64
2
+ from pathlib import Path
3
+ from typing import (
4
+ TYPE_CHECKING,
5
+ Any,
6
+ Callable,
7
+ Dict,
8
+ List,
9
+ Literal,
10
+ Optional,
11
+ Sequence,
12
+ Union,
13
+ cast,
14
+ )
15
+ from patchright._impl._api_structures import FilePayload, FloatRect, Position
16
+ from patchright._impl._connection import ChannelOwner, from_nullable_channel
17
+ from patchright._impl._helper import (
18
+ Error,
19
+ KeyboardModifier,
20
+ MouseButton,
21
+ async_writefile,
22
+ locals_to_params,
23
+ make_dirs_for_file,
24
+ )
25
+ from patchright._impl._js_handle import (
26
+ JSHandle,
27
+ Serializable,
28
+ parse_result,
29
+ serialize_argument,
30
+ )
31
+ from patchright._impl._set_input_files_helpers import convert_input_files
32
+
33
+ if TYPE_CHECKING:
34
+ from patchright._impl._frame import Frame
35
+ from patchright._impl._locator import Locator
36
+
37
+
38
+ class ElementHandle(JSHandle):
39
+ def __init__(
40
+ self, parent: ChannelOwner, type: str, guid: str, initializer: Dict
41
+ ) -> None:
42
+ super().__init__(parent, type, guid, initializer)
43
+ self._frame = cast("Frame", parent)
44
+
45
+ async def _createSelectorForTest(self, name: str) -> Optional[str]:
46
+ return await self._channel.send(
47
+ "createSelectorForTest", self._frame._timeout, dict(name=name)
48
+ )
49
+
50
+ def as_element(self) -> Optional["ElementHandle"]:
51
+ return self
52
+
53
+ async def owner_frame(self) -> Optional["Frame"]:
54
+ return from_nullable_channel(await self._channel.send("ownerFrame", None))
55
+
56
+ async def content_frame(self) -> Optional["Frame"]:
57
+ return from_nullable_channel(await self._channel.send("contentFrame", None))
58
+
59
+ async def get_attribute(self, name: str) -> Optional[str]:
60
+ return await self._channel.send("getAttribute", None, dict(name=name))
61
+
62
+ async def text_content(self) -> Optional[str]:
63
+ return await self._channel.send("textContent", None)
64
+
65
+ async def inner_text(self) -> str:
66
+ return await self._channel.send("innerText", None)
67
+
68
+ async def inner_html(self) -> str:
69
+ return await self._channel.send("innerHTML", None)
70
+
71
+ async def is_checked(self) -> bool:
72
+ return await self._channel.send("isChecked", None)
73
+
74
+ async def is_disabled(self) -> bool:
75
+ return await self._channel.send("isDisabled", None)
76
+
77
+ async def is_editable(self) -> bool:
78
+ return await self._channel.send("isEditable", None)
79
+
80
+ async def is_enabled(self) -> bool:
81
+ return await self._channel.send("isEnabled", None)
82
+
83
+ async def is_hidden(self) -> bool:
84
+ return await self._channel.send("isHidden", None)
85
+
86
+ async def is_visible(self) -> bool:
87
+ return await self._channel.send("isVisible", None)
88
+
89
+ async def dispatch_event(self, type: str, eventInit: Dict = None) -> None:
90
+ await self._channel.send(
91
+ "dispatchEvent",
92
+ None,
93
+ dict(type=type, eventInit=serialize_argument(eventInit)),
94
+ )
95
+
96
+ async def scroll_into_view_if_needed(self, timeout: float = None) -> None:
97
+ await self._channel.send(
98
+ "scrollIntoViewIfNeeded", self._frame._timeout, locals_to_params(locals())
99
+ )
100
+
101
+ async def hover(
102
+ self,
103
+ modifiers: Sequence[KeyboardModifier] = None,
104
+ position: Position = None,
105
+ timeout: float = None,
106
+ noWaitAfter: bool = None,
107
+ force: bool = None,
108
+ trial: bool = None,
109
+ scroll: Literal["auto", "none"] = None,
110
+ ) -> None:
111
+ await self._channel.send(
112
+ "hover", self._frame._timeout, locals_to_params(locals())
113
+ )
114
+
115
+ async def click(
116
+ self,
117
+ modifiers: Sequence[KeyboardModifier] = None,
118
+ position: Position = None,
119
+ delay: float = None,
120
+ button: MouseButton = None,
121
+ clickCount: int = None,
122
+ timeout: float = None,
123
+ force: bool = None,
124
+ noWaitAfter: bool = None,
125
+ trial: bool = None,
126
+ steps: int = None,
127
+ scroll: Literal["auto", "none"] = None,
128
+ ) -> None:
129
+ await self._channel.send(
130
+ "click", self._frame._timeout, locals_to_params(locals())
131
+ )
132
+
133
+ async def dblclick(
134
+ self,
135
+ modifiers: Sequence[KeyboardModifier] = None,
136
+ position: Position = None,
137
+ delay: float = None,
138
+ button: MouseButton = None,
139
+ timeout: float = None,
140
+ force: bool = None,
141
+ noWaitAfter: bool = None,
142
+ trial: bool = None,
143
+ steps: int = None,
144
+ scroll: Literal["auto", "none"] = None,
145
+ ) -> None:
146
+ await self._channel.send(
147
+ "dblclick", self._frame._timeout, locals_to_params(locals())
148
+ )
149
+
150
+ async def select_option(
151
+ self,
152
+ value: Union[str, Sequence[str]] = None,
153
+ index: Union[int, Sequence[int]] = None,
154
+ label: Union[str, Sequence[str]] = None,
155
+ element: Union["ElementHandle", Sequence["ElementHandle"]] = None,
156
+ timeout: float = None,
157
+ force: bool = None,
158
+ noWaitAfter: bool = None,
159
+ ) -> List[str]:
160
+ params = locals_to_params(
161
+ dict(
162
+ timeout=timeout,
163
+ force=force,
164
+ **convert_select_option_values(value, index, label, element),
165
+ )
166
+ )
167
+ return await self._channel.send("selectOption", self._frame._timeout, params)
168
+
169
+ async def tap(
170
+ self,
171
+ modifiers: Sequence[KeyboardModifier] = None,
172
+ position: Position = None,
173
+ timeout: float = None,
174
+ force: bool = None,
175
+ noWaitAfter: bool = None,
176
+ trial: bool = None,
177
+ scroll: Literal["auto", "none"] = None,
178
+ ) -> None:
179
+ await self._channel.send(
180
+ "tap", self._frame._timeout, locals_to_params(locals())
181
+ )
182
+
183
+ async def fill(
184
+ self,
185
+ value: str,
186
+ timeout: float = None,
187
+ noWaitAfter: bool = None,
188
+ force: bool = None,
189
+ ) -> None:
190
+ await self._channel.send(
191
+ "fill", self._frame._timeout, locals_to_params(locals())
192
+ )
193
+
194
+ async def select_text(self, force: bool = None, timeout: float = None) -> None:
195
+ await self._channel.send(
196
+ "selectText", self._frame._timeout, locals_to_params(locals())
197
+ )
198
+
199
+ async def input_value(self, timeout: float = None) -> str:
200
+ return await self._channel.send(
201
+ "inputValue", self._frame._timeout, locals_to_params(locals())
202
+ )
203
+
204
+ async def set_input_files(
205
+ self,
206
+ files: Union[
207
+ str, Path, FilePayload, Sequence[Union[str, Path]], Sequence[FilePayload]
208
+ ],
209
+ timeout: float = None,
210
+ noWaitAfter: bool = None,
211
+ ) -> None:
212
+ frame = await self.owner_frame()
213
+ if not frame:
214
+ raise Error("Cannot set input files to detached element")
215
+ converted = await convert_input_files(files, frame.page.context)
216
+ await self._channel.send(
217
+ "setInputFiles", self._frame._timeout, {"timeout": timeout, **converted}
218
+ )
219
+
220
+ async def focus(self) -> None:
221
+ await self._channel.send("focus", None)
222
+
223
+ async def type(
224
+ self,
225
+ text: str,
226
+ delay: float = None,
227
+ timeout: float = None,
228
+ noWaitAfter: bool = None,
229
+ ) -> None:
230
+ await self._channel.send(
231
+ "type", self._frame._timeout, locals_to_params(locals())
232
+ )
233
+
234
+ async def press(
235
+ self,
236
+ key: str,
237
+ delay: float = None,
238
+ timeout: float = None,
239
+ noWaitAfter: bool = None,
240
+ ) -> None:
241
+ await self._channel.send(
242
+ "press", self._frame._timeout, locals_to_params(locals())
243
+ )
244
+
245
+ async def set_checked(
246
+ self,
247
+ checked: bool,
248
+ position: Position = None,
249
+ timeout: float = None,
250
+ force: bool = None,
251
+ noWaitAfter: bool = None,
252
+ trial: bool = None,
253
+ scroll: Literal["auto", "none"] = None,
254
+ ) -> None:
255
+ if checked:
256
+ await self.check(
257
+ position=position,
258
+ timeout=timeout,
259
+ force=force,
260
+ trial=trial,
261
+ scroll=scroll,
262
+ )
263
+ else:
264
+ await self.uncheck(
265
+ position=position,
266
+ timeout=timeout,
267
+ force=force,
268
+ trial=trial,
269
+ scroll=scroll,
270
+ )
271
+
272
+ async def check(
273
+ self,
274
+ position: Position = None,
275
+ timeout: float = None,
276
+ force: bool = None,
277
+ noWaitAfter: bool = None,
278
+ trial: bool = None,
279
+ scroll: Literal["auto", "none"] = None,
280
+ ) -> None:
281
+ await self._channel.send(
282
+ "check", self._frame._timeout, locals_to_params(locals())
283
+ )
284
+
285
+ async def uncheck(
286
+ self,
287
+ position: Position = None,
288
+ timeout: float = None,
289
+ force: bool = None,
290
+ noWaitAfter: bool = None,
291
+ trial: bool = None,
292
+ scroll: Literal["auto", "none"] = None,
293
+ ) -> None:
294
+ await self._channel.send(
295
+ "uncheck", self._frame._timeout, locals_to_params(locals())
296
+ )
297
+
298
+ async def bounding_box(self) -> Optional[FloatRect]:
299
+ return await self._channel.send("boundingBox", None)
300
+
301
+ async def screenshot(
302
+ self,
303
+ timeout: float = None,
304
+ type: Literal["jpeg", "png", "webp"] = None,
305
+ path: Union[str, Path] = None,
306
+ quality: int = None,
307
+ omitBackground: bool = None,
308
+ animations: Literal["allow", "disabled"] = None,
309
+ caret: Literal["hide", "initial"] = None,
310
+ scale: Literal["css", "device"] = None,
311
+ mask: Sequence["Locator"] = None,
312
+ maskColor: str = None,
313
+ style: str = None,
314
+ ) -> bytes:
315
+ params = locals_to_params(locals())
316
+ if "path" in params:
317
+ if "type" not in params:
318
+ params["type"] = determine_screenshot_type(params["path"])
319
+ del params["path"]
320
+ if "mask" in params:
321
+ params["mask"] = list(
322
+ map(
323
+ lambda locator: {
324
+ "frame": locator._frame._channel,
325
+ "selector": locator._selector,
326
+ },
327
+ params["mask"],
328
+ )
329
+ )
330
+ encoded_binary = await self._channel.send(
331
+ "screenshot", self._frame._timeout, params
332
+ )
333
+ decoded_binary = base64.b64decode(encoded_binary)
334
+ if path:
335
+ make_dirs_for_file(path)
336
+ await async_writefile(path, decoded_binary)
337
+ return decoded_binary
338
+
339
+ async def query_selector(self, selector: str) -> Optional["ElementHandle"]:
340
+ return from_nullable_channel(
341
+ await self._channel.send("querySelector", None, dict(selector=selector))
342
+ )
343
+
344
+ async def query_selector_all(self, selector: str) -> List["ElementHandle"]:
345
+ return list(
346
+ map(
347
+ cast(Callable[[Any], Any], from_nullable_channel),
348
+ await self._channel.send(
349
+ "querySelectorAll", None, dict(selector=selector)
350
+ ),
351
+ )
352
+ )
353
+
354
+ async def eval_on_selector(
355
+ self, selector: str, expression: str, arg: Serializable = None
356
+ ) -> Any:
357
+ return parse_result(
358
+ await self._channel.send(
359
+ "evalOnSelector",
360
+ None,
361
+ dict(
362
+ selector=selector,
363
+ expression=expression,
364
+ arg=serialize_argument(arg),
365
+ ),
366
+ )
367
+ )
368
+
369
+ async def eval_on_selector_all(
370
+ self, selector: str, expression: str, arg: Serializable = None
371
+ ) -> Any:
372
+ return parse_result(
373
+ await self._channel.send(
374
+ "evalOnSelectorAll",
375
+ None,
376
+ dict(
377
+ selector=selector,
378
+ expression=expression,
379
+ arg=serialize_argument(arg),
380
+ ),
381
+ )
382
+ )
383
+
384
+ async def wait_for_element_state(
385
+ self,
386
+ state: Literal[
387
+ "disabled", "editable", "enabled", "hidden", "stable", "visible"
388
+ ],
389
+ timeout: float = None,
390
+ ) -> None:
391
+ await self._channel.send(
392
+ "waitForElementState", self._frame._timeout, locals_to_params(locals())
393
+ )
394
+
395
+ async def wait_for_selector(
396
+ self,
397
+ selector: str,
398
+ state: Literal["attached", "detached", "hidden", "visible"] = None,
399
+ timeout: float = None,
400
+ strict: bool = None,
401
+ ) -> Optional["ElementHandle"]:
402
+ return from_nullable_channel(
403
+ await self._channel.send(
404
+ "waitForSelector", self._frame._timeout, locals_to_params(locals())
405
+ )
406
+ )
407
+
408
+
409
+ def convert_select_option_values(
410
+ value: Union[str, Sequence[str]] = None,
411
+ index: Union[int, Sequence[int]] = None,
412
+ label: Union[str, Sequence[str]] = None,
413
+ element: Union["ElementHandle", Sequence["ElementHandle"]] = None,
414
+ ) -> Any:
415
+ if value is None and index is None and (label is None) and (element is None):
416
+ return {}
417
+ options: Any = None
418
+ elements: Any = None
419
+ if value is not None:
420
+ if isinstance(value, str):
421
+ value = [value]
422
+ options = (options or []) + list(map(lambda e: dict(valueOrLabel=e), value))
423
+ if index is not None:
424
+ if isinstance(index, int):
425
+ index = [index]
426
+ options = (options or []) + list(map(lambda e: dict(index=e), index))
427
+ if label is not None:
428
+ if isinstance(label, str):
429
+ label = [label]
430
+ options = (options or []) + list(map(lambda e: dict(label=e), label))
431
+ if element:
432
+ if isinstance(element, ElementHandle):
433
+ element = [element]
434
+ elements = list(map(lambda e: e._channel, element))
435
+ return dict(options=options, elements=elements)
436
+
437
+
438
+ def determine_screenshot_type(path: Union[str, Path]) -> Literal["jpeg", "png", "webp"]:
439
+ suffix = Path(path).suffix.lower()
440
+ if suffix == ".png":
441
+ return "png"
442
+ if suffix in (".jpeg", ".jpg"):
443
+ return "jpeg"
444
+ if suffix == ".webp":
445
+ return "webp"
446
+ raise Error(f'path: unsupported mime type "{suffix}"')
@@ -0,0 +1,46 @@
1
+ from typing import Any, List, Optional
2
+
3
+
4
+ def is_target_closed_error(error: Exception) -> bool:
5
+ return isinstance(error, TargetClosedError)
6
+
7
+
8
+ class Error(Exception):
9
+ def __init__(self, message: str) -> None:
10
+ self._message = message
11
+ self._name: Optional[str] = None
12
+ self._stack: Optional[str] = None
13
+ self._details: Optional[Any] = None
14
+ self._log: Optional[List[str]] = None
15
+ super().__init__(message)
16
+
17
+ @property
18
+ def message(self) -> str:
19
+ return self._message
20
+
21
+ @property
22
+ def name(self) -> Optional[str]:
23
+ return self._name
24
+
25
+ @property
26
+ def stack(self) -> Optional[str]:
27
+ return self._stack
28
+
29
+
30
+ class TimeoutError(Error):
31
+ pass
32
+
33
+
34
+ class TargetClosedError(Error):
35
+ def __init__(self, message: str = None) -> None:
36
+ super().__init__(message or "Target page, context or browser has been closed")
37
+
38
+
39
+ def rewrite_error(error: Exception, message: str) -> Exception:
40
+ rewritten_exc = type(error)(message)
41
+ if isinstance(rewritten_exc, Error) and isinstance(error, Error):
42
+ rewritten_exc._name = error.name
43
+ rewritten_exc._stack = error.stack
44
+ rewritten_exc._details = error._details
45
+ rewritten_exc._log = error._log
46
+ return rewritten_exc
@@ -0,0 +1,19 @@
1
+ import asyncio
2
+ from typing import Any, Generic, TypeVar
3
+
4
+ T = TypeVar("T")
5
+
6
+
7
+ class EventContextManagerImpl(Generic[T]):
8
+ def __init__(self, future: asyncio.Future) -> None:
9
+ self._future: asyncio.Future = future
10
+
11
+ @property
12
+ def future(self) -> asyncio.Future:
13
+ return self._future
14
+
15
+ async def __aenter__(self) -> asyncio.Future:
16
+ return self._future
17
+
18
+ async def __aexit__(self, *args: Any) -> None:
19
+ await self._future