osn-selenium 0.0.0__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.
- osn_selenium/__init__.py +1 -0
- osn_selenium/browsers_handler/__init__.py +70 -0
- osn_selenium/browsers_handler/_windows.py +130 -0
- osn_selenium/browsers_handler/types.py +20 -0
- osn_selenium/captcha_workers/__init__.py +26 -0
- osn_selenium/dev_tools/__init__.py +1 -0
- osn_selenium/dev_tools/_types.py +22 -0
- osn_selenium/dev_tools/domains/__init__.py +63 -0
- osn_selenium/dev_tools/domains/abstract.py +378 -0
- osn_selenium/dev_tools/domains/fetch.py +1295 -0
- osn_selenium/dev_tools/domains_default/__init__.py +1 -0
- osn_selenium/dev_tools/domains_default/fetch.py +155 -0
- osn_selenium/dev_tools/errors.py +89 -0
- osn_selenium/dev_tools/logger.py +558 -0
- osn_selenium/dev_tools/manager.py +1551 -0
- osn_selenium/dev_tools/utils.py +509 -0
- osn_selenium/errors.py +16 -0
- osn_selenium/types.py +118 -0
- osn_selenium/webdrivers/BaseDriver/__init__.py +1 -0
- osn_selenium/webdrivers/BaseDriver/_utils.py +37 -0
- osn_selenium/webdrivers/BaseDriver/flags.py +644 -0
- osn_selenium/webdrivers/BaseDriver/protocols.py +2135 -0
- osn_selenium/webdrivers/BaseDriver/trio_wrapper.py +71 -0
- osn_selenium/webdrivers/BaseDriver/webdriver.py +2626 -0
- osn_selenium/webdrivers/Blink/__init__.py +1 -0
- osn_selenium/webdrivers/Blink/flags.py +1349 -0
- osn_selenium/webdrivers/Blink/protocols.py +330 -0
- osn_selenium/webdrivers/Blink/webdriver.py +637 -0
- osn_selenium/webdrivers/Chrome/__init__.py +1 -0
- osn_selenium/webdrivers/Chrome/flags.py +192 -0
- osn_selenium/webdrivers/Chrome/protocols.py +228 -0
- osn_selenium/webdrivers/Chrome/webdriver.py +394 -0
- osn_selenium/webdrivers/Edge/__init__.py +1 -0
- osn_selenium/webdrivers/Edge/flags.py +192 -0
- osn_selenium/webdrivers/Edge/protocols.py +228 -0
- osn_selenium/webdrivers/Edge/webdriver.py +394 -0
- osn_selenium/webdrivers/Yandex/__init__.py +1 -0
- osn_selenium/webdrivers/Yandex/flags.py +192 -0
- osn_selenium/webdrivers/Yandex/protocols.py +211 -0
- osn_selenium/webdrivers/Yandex/webdriver.py +350 -0
- osn_selenium/webdrivers/__init__.py +1 -0
- osn_selenium/webdrivers/_functions.py +504 -0
- osn_selenium/webdrivers/js_scripts/check_element_in_viewport.js +18 -0
- osn_selenium/webdrivers/js_scripts/get_document_scroll_size.js +4 -0
- osn_selenium/webdrivers/js_scripts/get_element_css.js +6 -0
- osn_selenium/webdrivers/js_scripts/get_element_rect_in_viewport.js +9 -0
- osn_selenium/webdrivers/js_scripts/get_random_element_point_in_viewport.js +59 -0
- osn_selenium/webdrivers/js_scripts/get_viewport_position.js +4 -0
- osn_selenium/webdrivers/js_scripts/get_viewport_rect.js +6 -0
- osn_selenium/webdrivers/js_scripts/get_viewport_size.js +4 -0
- osn_selenium/webdrivers/js_scripts/open_new_tab.js +1 -0
- osn_selenium/webdrivers/js_scripts/stop_window_loading.js +1 -0
- osn_selenium/webdrivers/types.py +390 -0
- osn_selenium-0.0.0.dist-info/METADATA +710 -0
- osn_selenium-0.0.0.dist-info/RECORD +57 -0
- osn_selenium-0.0.0.dist-info/WHEEL +5 -0
- osn_selenium-0.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
import trio
|
|
2
|
+
from typing import (
|
|
3
|
+
Any,
|
|
4
|
+
Awaitable,
|
|
5
|
+
Callable,
|
|
6
|
+
Mapping,
|
|
7
|
+
Optional,
|
|
8
|
+
Sequence,
|
|
9
|
+
TYPE_CHECKING,
|
|
10
|
+
TypedDict
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
if TYPE_CHECKING:
|
|
15
|
+
from osn_selenium.dev_tools.manager import DevToolsTarget
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class ParameterHandler(TypedDict):
|
|
19
|
+
"""
|
|
20
|
+
A dictionary defining a parameter handler function and its instances.
|
|
21
|
+
|
|
22
|
+
This structure is used within action configurations to specify a function
|
|
23
|
+
that will generate or modify a specific parameter for a CDP command.
|
|
24
|
+
|
|
25
|
+
Attributes:
|
|
26
|
+
func (parameter_handler_type): The handler function to be executed. This function should modify a `kwargs` dictionary used for a CDP command.
|
|
27
|
+
instances (Any): The data or configuration specific to this handler instance, passed as the `instances` argument to the `func`.
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
func: "parameter_handler_type"
|
|
31
|
+
instances: Any
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class AbstractEventActionsSettings:
|
|
35
|
+
"""
|
|
36
|
+
Abstract base class for settings related to actions triggered by a specific event.
|
|
37
|
+
|
|
38
|
+
Subclasses should define attributes corresponding to the possible actions
|
|
39
|
+
for the event and implement the `to_dict` method.
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
def to_dict(self) -> "AbstractEventActions":
|
|
43
|
+
"""
|
|
44
|
+
Converts the settings object to its dictionary representation.
|
|
45
|
+
|
|
46
|
+
Returns:
|
|
47
|
+
AbstractEventActions: A dictionary mapping action names to their configurations.
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
raise NotImplementedError("This method must be implemented in a subclass.")
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class AbstractEventActionsHandler(TypedDict):
|
|
54
|
+
"""
|
|
55
|
+
Abstract TypedDict for the configuration of an event's actions handler.
|
|
56
|
+
|
|
57
|
+
This structure defines how to choose and configure the actions to take
|
|
58
|
+
when a specific DevTools event occurs.
|
|
59
|
+
|
|
60
|
+
Attributes:
|
|
61
|
+
choose_action_func (event_choose_action_func_type): A function that determines which actions (by name) should be executed for a given event.
|
|
62
|
+
actions (AnyMapping): A dictionary mapping action names (strings) to their full configurations (AbstractAction).
|
|
63
|
+
"""
|
|
64
|
+
|
|
65
|
+
choose_action_func: "event_choose_action_func_type"
|
|
66
|
+
actions: "AnyMapping"
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
class AbstractEventActionsHandlerSettings:
|
|
70
|
+
"""
|
|
71
|
+
Abstract base class for settings related to an event's actions handler.
|
|
72
|
+
|
|
73
|
+
Subclasses should define attributes for the `choose_action_func` and
|
|
74
|
+
`actions` settings and implement the `to_dict` method.
|
|
75
|
+
|
|
76
|
+
Attributes:
|
|
77
|
+
choose_action_func (event_choose_action_func_type): A function that determines which actions (by name) should be executed for a given event.
|
|
78
|
+
actions (AbstractEventActionsSettings): Settings for the available actions.
|
|
79
|
+
"""
|
|
80
|
+
|
|
81
|
+
choose_action_func: "event_choose_action_func_type"
|
|
82
|
+
actions: AbstractEventActionsSettings
|
|
83
|
+
|
|
84
|
+
def to_dict(self) -> AbstractEventActionsHandler:
|
|
85
|
+
"""
|
|
86
|
+
Converts the settings object to its dictionary representation.
|
|
87
|
+
|
|
88
|
+
Returns:
|
|
89
|
+
AbstractEventActionsHandler: A dictionary representation of the actions handler settings.
|
|
90
|
+
"""
|
|
91
|
+
|
|
92
|
+
raise NotImplementedError("This method must be implemented in a subclass.")
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
class AbstractEvent(TypedDict):
|
|
96
|
+
"""
|
|
97
|
+
Abstract TypedDict representing the configuration for a CDP event listener.
|
|
98
|
+
|
|
99
|
+
This structure defines the common components needed to listen for and handle
|
|
100
|
+
a specific Chrome DevTools Protocol (CDP) event.
|
|
101
|
+
|
|
102
|
+
Attributes:
|
|
103
|
+
class_to_use_path (str): The dot-separated path to the CDP event class (e.g., "fetch.RequestPaused").
|
|
104
|
+
listen_buffer_size (int): The buffer size for the event listener channel.
|
|
105
|
+
handle_function (AnyCallable): The asynchronous function to execute when an event is received.
|
|
106
|
+
actions_handler (AnyMapping): A dictionary of callback functions and settings specific to the event handler.
|
|
107
|
+
on_error_func (on_error_func_type): An optional function to call if an error occurs during event handling.
|
|
108
|
+
"""
|
|
109
|
+
|
|
110
|
+
class_to_use_path: str
|
|
111
|
+
listen_buffer_size: int
|
|
112
|
+
handle_function: "AnyCallable"
|
|
113
|
+
actions_handler: "AnyMapping"
|
|
114
|
+
on_error_func: "on_error_func_type"
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
class AbstractEventSettings:
|
|
118
|
+
"""
|
|
119
|
+
Abstract base class for settings related to a specific DevTools event listener.
|
|
120
|
+
|
|
121
|
+
Subclasses should define attributes for buffer size, actions handler,
|
|
122
|
+
and error function, and implement the abstract properties and `to_dict` method.
|
|
123
|
+
|
|
124
|
+
Attributes:
|
|
125
|
+
listen_buffer_size (int): The buffer size for the event listener channel.
|
|
126
|
+
actions_handler (AbstractEventActionsHandlerSettings): Configuration for the event's actions handler.
|
|
127
|
+
on_error_func (on_error_func_type): An optional function to call if an error occurs during event handling.
|
|
128
|
+
"""
|
|
129
|
+
|
|
130
|
+
listen_buffer_size: int
|
|
131
|
+
actions_handler: AbstractEventActionsHandlerSettings
|
|
132
|
+
on_error_func: "on_error_func_type"
|
|
133
|
+
|
|
134
|
+
@property
|
|
135
|
+
def class_to_use_path(self) -> str:
|
|
136
|
+
"""
|
|
137
|
+
Returns the dot-separated path to the corresponding CDP event class.
|
|
138
|
+
|
|
139
|
+
Returns:
|
|
140
|
+
str: The path string.
|
|
141
|
+
"""
|
|
142
|
+
|
|
143
|
+
raise NotImplementedError("This method must be implemented in a subclass.")
|
|
144
|
+
|
|
145
|
+
@property
|
|
146
|
+
def handle_function(self) -> "handle_function":
|
|
147
|
+
"""
|
|
148
|
+
Returns the main asynchronous handler function for this event.
|
|
149
|
+
|
|
150
|
+
Returns:
|
|
151
|
+
handle_function: The handler function.
|
|
152
|
+
"""
|
|
153
|
+
|
|
154
|
+
raise NotImplementedError("This method must be implemented in a subclass.")
|
|
155
|
+
|
|
156
|
+
def to_dict(self) -> AbstractEvent:
|
|
157
|
+
"""
|
|
158
|
+
Converts the settings object to its dictionary representation.
|
|
159
|
+
|
|
160
|
+
Returns:
|
|
161
|
+
AbstractEvent: A dictionary representation of the event settings.
|
|
162
|
+
"""
|
|
163
|
+
|
|
164
|
+
raise NotImplementedError("This method must be implemented in a subclass.")
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
class AbstractDomainHandlersSettings:
|
|
168
|
+
"""
|
|
169
|
+
Abstract base class for container of all handler settings within a DevTools domain.
|
|
170
|
+
|
|
171
|
+
Subclasses should define attributes for each event handler within the domain
|
|
172
|
+
and implement the `to_dict` method.
|
|
173
|
+
"""
|
|
174
|
+
|
|
175
|
+
def to_dict(self) -> "AbstractDomainHandlers":
|
|
176
|
+
"""
|
|
177
|
+
Converts the settings object to its dictionary representation.
|
|
178
|
+
|
|
179
|
+
Returns:
|
|
180
|
+
AbstractDomainHandlers: A dictionary mapping event names to their handler configurations.
|
|
181
|
+
"""
|
|
182
|
+
|
|
183
|
+
raise NotImplementedError("This method must be implemented in a subclass.")
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
class AbstractDomainEnableKwargsSettings:
|
|
187
|
+
"""
|
|
188
|
+
Abstract base class for keyword arguments used to enable a DevTools domain.
|
|
189
|
+
|
|
190
|
+
Subclasses should define attributes corresponding to the parameters
|
|
191
|
+
of the domain's enable function and implement the `to_dict` method.
|
|
192
|
+
"""
|
|
193
|
+
|
|
194
|
+
def to_dict(self) -> "AbstractDomainEnableKwargs":
|
|
195
|
+
"""
|
|
196
|
+
Converts the settings object to its dictionary representation.
|
|
197
|
+
|
|
198
|
+
Returns:
|
|
199
|
+
AbstractDomainEnableKwargs: A dictionary of keyword arguments for the enable function.
|
|
200
|
+
"""
|
|
201
|
+
|
|
202
|
+
raise NotImplementedError("This method must be implemented in a subclass.")
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
class AbstractDomain(TypedDict):
|
|
206
|
+
"""
|
|
207
|
+
Abstract TypedDict for the complete configuration of a DevTools domain.
|
|
208
|
+
|
|
209
|
+
This structure is used internally by the DevTools manager to configure a
|
|
210
|
+
specific domain, including how to enable/disable it and what event handlers to use.
|
|
211
|
+
|
|
212
|
+
Attributes:
|
|
213
|
+
name (str): The name of the domain (e.g., 'fetch').
|
|
214
|
+
enable_func_path (str): The dot-separated path to the function to enable the domain (e.g., "fetch.enable").
|
|
215
|
+
enable_func_kwargs (Optional[AnyMapping]): Keyword arguments for the enable function.
|
|
216
|
+
disable_func_path (str): The dot-separated path to the function to disable the domain (e.g., "fetch.disable").
|
|
217
|
+
handlers (AnyMapping): A dictionary mapping event names to their configured handlers (AbstractEvent).
|
|
218
|
+
"""
|
|
219
|
+
|
|
220
|
+
name: str
|
|
221
|
+
enable_func_path: str
|
|
222
|
+
enable_func_kwargs: Optional["AnyMapping"]
|
|
223
|
+
disable_func_path: str
|
|
224
|
+
handlers: "AnyMapping"
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
class AbstractDomainSettings:
|
|
228
|
+
"""
|
|
229
|
+
Abstract base class for the top-level configuration of a DevTools domain.
|
|
230
|
+
|
|
231
|
+
Subclasses should define attributes for enable keyword arguments and handlers,
|
|
232
|
+
and implement the abstract properties and `to_dict` method.
|
|
233
|
+
|
|
234
|
+
Attributes:
|
|
235
|
+
enable_func_kwargs (Optional[AbstractDomainEnableKwargsSettings]): Keyword arguments for enabling the domain.
|
|
236
|
+
handlers (AbstractDomainHandlersSettings): Container for all handler settings within the domain.
|
|
237
|
+
"""
|
|
238
|
+
|
|
239
|
+
enable_func_kwargs: Optional[AbstractDomainEnableKwargsSettings]
|
|
240
|
+
handlers: AbstractDomainHandlersSettings
|
|
241
|
+
|
|
242
|
+
@property
|
|
243
|
+
def disable_func_path(self) -> str:
|
|
244
|
+
"""
|
|
245
|
+
Returns the dot-separated path to the function used to disable the domain.
|
|
246
|
+
|
|
247
|
+
Returns:
|
|
248
|
+
str: The path string.
|
|
249
|
+
"""
|
|
250
|
+
|
|
251
|
+
raise NotImplementedError("This method must be implemented in a subclass.")
|
|
252
|
+
|
|
253
|
+
@property
|
|
254
|
+
def enable_func_path(self) -> str:
|
|
255
|
+
"""
|
|
256
|
+
Returns the dot-separated path to the function used to enable the domain.
|
|
257
|
+
|
|
258
|
+
Returns:
|
|
259
|
+
str: The path string.
|
|
260
|
+
"""
|
|
261
|
+
|
|
262
|
+
raise NotImplementedError("This method must be implemented in a subclass.")
|
|
263
|
+
|
|
264
|
+
@property
|
|
265
|
+
def name(self) -> str:
|
|
266
|
+
"""
|
|
267
|
+
Returns the name of the DevTools domain.
|
|
268
|
+
|
|
269
|
+
Returns:
|
|
270
|
+
str: The domain name.
|
|
271
|
+
"""
|
|
272
|
+
|
|
273
|
+
raise NotImplementedError("This method must be implemented in a subclass.")
|
|
274
|
+
|
|
275
|
+
def to_dict(self) -> AbstractDomain:
|
|
276
|
+
"""
|
|
277
|
+
Converts the settings object to its dictionary representation.
|
|
278
|
+
|
|
279
|
+
Returns:
|
|
280
|
+
AbstractDomain: A dictionary representation of the domain settings.
|
|
281
|
+
"""
|
|
282
|
+
|
|
283
|
+
raise NotImplementedError("This method must be implemented in a subclass.")
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
class AbstractActionParametersHandlersSettings:
|
|
287
|
+
"""
|
|
288
|
+
Abstract base class for settings related to parameter handlers for a specific action.
|
|
289
|
+
|
|
290
|
+
Subclasses should define attributes corresponding to the parameters
|
|
291
|
+
of the action's CDP command and implement the `to_dict` method.
|
|
292
|
+
"""
|
|
293
|
+
|
|
294
|
+
def to_dict(self) -> "AbstractActionParametersHandlers":
|
|
295
|
+
"""
|
|
296
|
+
Converts the settings object to its dictionary representation.
|
|
297
|
+
|
|
298
|
+
Returns:
|
|
299
|
+
AbstractActionParametersHandlers: A dictionary mapping parameter names to their handler configurations.
|
|
300
|
+
"""
|
|
301
|
+
|
|
302
|
+
raise NotImplementedError("This method must be implemented in a subclass.")
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
class AbstractAction(TypedDict):
|
|
306
|
+
"""
|
|
307
|
+
Abstract TypedDict for the configuration of a specific action triggered by an event.
|
|
308
|
+
|
|
309
|
+
This structure defines how to build the arguments for a CDP command
|
|
310
|
+
and how to handle its response.
|
|
311
|
+
|
|
312
|
+
Attributes:
|
|
313
|
+
kwargs_func (build_kwargs_from_handlers_func_type): Function to build keyword arguments for the CDP command.
|
|
314
|
+
response_handle_func (response_handle_func_type): An optional function to process the response from the CDP command.
|
|
315
|
+
parameters_handlers (AnyMapping): A dictionary mapping parameter names to their handler configurations (ParameterHandler).
|
|
316
|
+
"""
|
|
317
|
+
|
|
318
|
+
kwargs_func: "build_kwargs_from_handlers_func_type"
|
|
319
|
+
response_handle_func: "response_handle_func_type"
|
|
320
|
+
parameters_handlers: "AnyMapping"
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
class AbstractActionSettings:
|
|
324
|
+
"""
|
|
325
|
+
Abstract base class for settings related to a specific action triggered by an event.
|
|
326
|
+
|
|
327
|
+
Subclasses should define attributes for response handling and parameter handlers,
|
|
328
|
+
and implement the abstract property and `to_dict` method.
|
|
329
|
+
|
|
330
|
+
Attributes:
|
|
331
|
+
response_handle_func (response_handle_func_type): An optional function to process the response from the CDP command.
|
|
332
|
+
parameters_handlers (AbstractActionParametersHandlersSettings): Settings for the action's parameter handlers.
|
|
333
|
+
"""
|
|
334
|
+
|
|
335
|
+
response_handle_func: "response_handle_func_type"
|
|
336
|
+
parameters_handlers: AbstractActionParametersHandlersSettings
|
|
337
|
+
|
|
338
|
+
@property
|
|
339
|
+
def kwargs_func(self) -> "build_kwargs_from_handlers_func_type":
|
|
340
|
+
"""
|
|
341
|
+
Returns the function used to build keyword arguments for the action's CDP command.
|
|
342
|
+
|
|
343
|
+
Returns:
|
|
344
|
+
build_kwargs_from_handlers_func_type: The kwargs building function.
|
|
345
|
+
"""
|
|
346
|
+
|
|
347
|
+
raise NotImplementedError("This method must be implemented in a subclass.")
|
|
348
|
+
|
|
349
|
+
def to_dict(self) -> AbstractAction:
|
|
350
|
+
"""
|
|
351
|
+
Converts the settings object to its dictionary representation.
|
|
352
|
+
|
|
353
|
+
Returns:
|
|
354
|
+
AbstractAction: A dictionary representation of the action settings.
|
|
355
|
+
"""
|
|
356
|
+
|
|
357
|
+
raise NotImplementedError("This method must be implemented in a subclass.")
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
kwargs_type = dict[str, Any]
|
|
361
|
+
kwargs_output_type = Awaitable[kwargs_type]
|
|
362
|
+
build_kwargs_from_handlers_func_type = Optional[
|
|
363
|
+
Callable[
|
|
364
|
+
["DevToolsTarget", Mapping[str, Optional[ParameterHandler]], Any],
|
|
365
|
+
kwargs_output_type
|
|
366
|
+
]
|
|
367
|
+
]
|
|
368
|
+
parameter_handler_type = Callable[["DevToolsTarget", trio.Event, Any, Any, dict[str, Any]], Awaitable[None]]
|
|
369
|
+
event_choose_action_func_type = Callable[["DevToolsTarget", Any], Sequence[str]]
|
|
370
|
+
handle_function = Callable[["DevToolsTarget", Any, Any], Awaitable[None]]
|
|
371
|
+
response_handle_func_type = Optional[Callable[["DevToolsTarget", Any], Awaitable[Any]]]
|
|
372
|
+
on_error_func_type = Optional[Callable[["DevToolsTarget", Any, BaseException], None]]
|
|
373
|
+
AnyMapping = Mapping[str, Any]
|
|
374
|
+
AnyCallable = Callable[..., Any]
|
|
375
|
+
AbstractDomainHandlers = Mapping[str, AbstractEvent]
|
|
376
|
+
AbstractDomainEnableKwargs = Mapping[str, Any]
|
|
377
|
+
AbstractEventActions = Mapping[str, AbstractAction]
|
|
378
|
+
AbstractActionParametersHandlers = Mapping[str, ParameterHandler]
|