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.
Files changed (57) hide show
  1. osn_selenium/__init__.py +1 -0
  2. osn_selenium/browsers_handler/__init__.py +70 -0
  3. osn_selenium/browsers_handler/_windows.py +130 -0
  4. osn_selenium/browsers_handler/types.py +20 -0
  5. osn_selenium/captcha_workers/__init__.py +26 -0
  6. osn_selenium/dev_tools/__init__.py +1 -0
  7. osn_selenium/dev_tools/_types.py +22 -0
  8. osn_selenium/dev_tools/domains/__init__.py +63 -0
  9. osn_selenium/dev_tools/domains/abstract.py +378 -0
  10. osn_selenium/dev_tools/domains/fetch.py +1295 -0
  11. osn_selenium/dev_tools/domains_default/__init__.py +1 -0
  12. osn_selenium/dev_tools/domains_default/fetch.py +155 -0
  13. osn_selenium/dev_tools/errors.py +89 -0
  14. osn_selenium/dev_tools/logger.py +558 -0
  15. osn_selenium/dev_tools/manager.py +1551 -0
  16. osn_selenium/dev_tools/utils.py +509 -0
  17. osn_selenium/errors.py +16 -0
  18. osn_selenium/types.py +118 -0
  19. osn_selenium/webdrivers/BaseDriver/__init__.py +1 -0
  20. osn_selenium/webdrivers/BaseDriver/_utils.py +37 -0
  21. osn_selenium/webdrivers/BaseDriver/flags.py +644 -0
  22. osn_selenium/webdrivers/BaseDriver/protocols.py +2135 -0
  23. osn_selenium/webdrivers/BaseDriver/trio_wrapper.py +71 -0
  24. osn_selenium/webdrivers/BaseDriver/webdriver.py +2626 -0
  25. osn_selenium/webdrivers/Blink/__init__.py +1 -0
  26. osn_selenium/webdrivers/Blink/flags.py +1349 -0
  27. osn_selenium/webdrivers/Blink/protocols.py +330 -0
  28. osn_selenium/webdrivers/Blink/webdriver.py +637 -0
  29. osn_selenium/webdrivers/Chrome/__init__.py +1 -0
  30. osn_selenium/webdrivers/Chrome/flags.py +192 -0
  31. osn_selenium/webdrivers/Chrome/protocols.py +228 -0
  32. osn_selenium/webdrivers/Chrome/webdriver.py +394 -0
  33. osn_selenium/webdrivers/Edge/__init__.py +1 -0
  34. osn_selenium/webdrivers/Edge/flags.py +192 -0
  35. osn_selenium/webdrivers/Edge/protocols.py +228 -0
  36. osn_selenium/webdrivers/Edge/webdriver.py +394 -0
  37. osn_selenium/webdrivers/Yandex/__init__.py +1 -0
  38. osn_selenium/webdrivers/Yandex/flags.py +192 -0
  39. osn_selenium/webdrivers/Yandex/protocols.py +211 -0
  40. osn_selenium/webdrivers/Yandex/webdriver.py +350 -0
  41. osn_selenium/webdrivers/__init__.py +1 -0
  42. osn_selenium/webdrivers/_functions.py +504 -0
  43. osn_selenium/webdrivers/js_scripts/check_element_in_viewport.js +18 -0
  44. osn_selenium/webdrivers/js_scripts/get_document_scroll_size.js +4 -0
  45. osn_selenium/webdrivers/js_scripts/get_element_css.js +6 -0
  46. osn_selenium/webdrivers/js_scripts/get_element_rect_in_viewport.js +9 -0
  47. osn_selenium/webdrivers/js_scripts/get_random_element_point_in_viewport.js +59 -0
  48. osn_selenium/webdrivers/js_scripts/get_viewport_position.js +4 -0
  49. osn_selenium/webdrivers/js_scripts/get_viewport_rect.js +6 -0
  50. osn_selenium/webdrivers/js_scripts/get_viewport_size.js +4 -0
  51. osn_selenium/webdrivers/js_scripts/open_new_tab.js +1 -0
  52. osn_selenium/webdrivers/js_scripts/stop_window_loading.js +1 -0
  53. osn_selenium/webdrivers/types.py +390 -0
  54. osn_selenium-0.0.0.dist-info/METADATA +710 -0
  55. osn_selenium-0.0.0.dist-info/RECORD +57 -0
  56. osn_selenium-0.0.0.dist-info/WHEEL +5 -0
  57. osn_selenium-0.0.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,330 @@
1
+ import pathlib
2
+ from selenium import webdriver
3
+ from osn_selenium.types import WindowRect
4
+ from osn_selenium.webdrivers.types import _any_flags_mapping
5
+ from typing import (
6
+ Optional,
7
+ Protocol,
8
+ TYPE_CHECKING,
9
+ Union,
10
+ runtime_checkable
11
+ )
12
+ from osn_selenium.webdrivers.BaseDriver.protocols import (
13
+ TrioWebDriverWrapperProtocol
14
+ )
15
+
16
+
17
+ if TYPE_CHECKING:
18
+ from osn_selenium.webdrivers.Blink.webdriver import BlinkWebDriver
19
+ from osn_selenium.webdrivers.Blink.flags import BlinkFlagsManager, BlinkFlags
20
+
21
+
22
+ @runtime_checkable
23
+ class TrioBlinkWebDriverWrapperProtocol(TrioWebDriverWrapperProtocol, Protocol):
24
+ """
25
+ Wraps BlinkWebDriver methods for asynchronous execution using Trio.
26
+
27
+ This class acts as a proxy to a `BrowserWebDriver` instance. It intercepts
28
+ method calls and executes them in a separate thread using `trio.to_thread.run_sync`,
29
+ allowing synchronous WebDriver operations to be called from asynchronous Trio code
30
+ without blocking the event loop. Properties and non-callable attributes are accessed directly.
31
+
32
+ Attributes:
33
+ _webdriver (BrowserWebDriver): The underlying synchronous BrowserWebDriver instance.
34
+ _excluding_functions (list[str]): A list of attribute names on the wrapped object
35
+ that should *not* be accessible through this wrapper,
36
+ typically because they are irrelevant or dangerous
37
+ in an async context handled by the wrapper.
38
+ """
39
+
40
+ _webdriver: "BlinkWebDriver"
41
+ _webdriver_flags_manager: "BlinkFlagsManager"
42
+ _driver: Optional[Union[webdriver.Chrome, webdriver.Edge]]
43
+
44
+ async def _check_browser_exe_active(self) -> bool:
45
+ """
46
+ Checks if the WebDriver is active by verifying if the debugging port is in use.
47
+
48
+ Determines if a WebDriver instance is currently running and active by checking if the configured
49
+ debugging port is in use by any process. This is a way to verify if a browser session is active
50
+ without directly querying the WebDriver itself.
51
+
52
+ Returns:
53
+ bool: True if the WebDriver is active (debugging port is in use), False otherwise.
54
+ """
55
+
56
+ ...
57
+
58
+ async def _find_debugging_port(self, debugging_port: Optional[int]) -> int:
59
+ """
60
+ Finds an appropriate debugging port, either reusing a previous session's port or finding a free port.
61
+
62
+ Attempts to locate a suitable debugging port for the browser. It first tries to reuse a debugging port
63
+ from a previous browser session if a profile directory is specified and a previous session is found.
64
+ If no previous session is found or if no profile directory is specified, it attempts to use the provided
65
+ `debugging_port` if available, or finds a minimum free port if no port is provided or the provided port is in use.
66
+
67
+ Args:
68
+ debugging_port (Optional[int]): Requested debugging port number. If provided, the method attempts to use this port. Defaults to None.
69
+
70
+ Returns:
71
+ int: The debugging port number to use. This is either a reused port from a previous session, the provided port if available, or a newly found free port.
72
+ """
73
+
74
+ ...
75
+
76
+ async def _set_debugging_port(self, debugging_port: Optional[int], debugging_address: Optional[str]):
77
+ """
78
+ Sets the debugging port and address.
79
+
80
+ Configures the browser to start with a specific debugging port. This port is used for external tools,
81
+ like debuggers or browser automation frameworks, to connect to and control the browser instance.
82
+ Setting a fixed debugging port can be useful for consistent remote debugging or automation setups.
83
+
84
+ Args:
85
+ debugging_port (Optional[int]): Debugging port number. If None or 0, the browser chooses a port automatically.
86
+ debugging_address (Optional[str]): The IP address for the debugger to listen on. Defaults to '127.0.0.1'.
87
+ """
88
+
89
+ ...
90
+
91
+ @property
92
+ def browser_exe(self) -> Optional[Union[str, pathlib.Path]]:
93
+ """
94
+ Gets the path to the browser executable.
95
+
96
+ Returns:
97
+ Optional[Union[str, pathlib.Path]]: The path to the browser executable.
98
+ """
99
+
100
+ ...
101
+
102
+ async def close_webdriver(self):
103
+ """
104
+ Closes the WebDriver instance and terminates the associated browser subprocess.
105
+
106
+ Quits the current WebDriver session, closes all browser windows, and then forcefully terminates
107
+ the browser process. This ensures a clean shutdown of the browser and WebDriver environment.
108
+ """
109
+
110
+ ...
111
+
112
+ @property
113
+ def debugging_ip(self) -> Optional[str]:
114
+ """
115
+ Gets the IP address part of the debugger address.
116
+
117
+ Returns:
118
+ Optional[str]: The IP address of the debugger, or None if not set.
119
+ """
120
+
121
+ ...
122
+
123
+ @property
124
+ def debugging_port(self) -> Optional[int]:
125
+ """
126
+ Gets the currently set debugging port.
127
+
128
+ Retrieves the debugging port number that the browser instance is configured to use.
129
+
130
+ Returns:
131
+ Optional[int]: The debugging port number, or None if not set.
132
+ """
133
+
134
+ ...
135
+
136
+ @property
137
+ def driver(self) -> Optional[Union[webdriver.Chrome, webdriver.Edge]]:
138
+ """
139
+ Gets the underlying Selenium WebDriver instance associated with this object.
140
+
141
+ This property provides direct access to the WebDriver object (e.g., Chrome, Edge)
142
+ that is being controlled, allowing for direct Selenium operations if needed.
143
+
144
+ Returns:
145
+ Optional[Union[webdriver.Chrome, webdriver.Edge]]:
146
+ The active WebDriver instance, or None if no driver is currently set or active.
147
+ """
148
+
149
+ ...
150
+
151
+ def reset_settings(
152
+ self,
153
+ flags: Optional[Union["BlinkFlags", _any_flags_mapping]] = None,
154
+ browser_exe: Optional[Union[str, pathlib.Path]] = None,
155
+ browser_name_in_system: Optional[str] = None,
156
+ use_browser_exe: Optional[bool] = None,
157
+ start_page_url: str = "",
158
+ window_rect: Optional[WindowRect] = None,
159
+ trio_tokens_limit: Union[int, float] = 40,
160
+ ):
161
+ """
162
+ Resets various configurable browser settings to their specified or default values.
163
+
164
+ This method allows for reconfiguring the WebDriver's operational parameters,
165
+ such as browser flags, executable path, start URL, window dimensions, and
166
+ concurrency limits. It is crucial that the browser session is *not* active
167
+ when this method is called; otherwise, a warning will be issued, and no changes
168
+ will be applied.
169
+
170
+ Args:
171
+ flags (Optional[Union[BlinkFlags, Mapping[str, Any]]]): New browser flags to apply.
172
+ If provided, existing flags are cleared and replaced with these.
173
+ If `None`, all custom flags are cleared, and the browser will start with default flags.
174
+ browser_exe (Optional[Union[str, pathlib.Path]]): The explicit path to the browser executable.
175
+ If provided, this path will be used. If `None`, the executable path managed by the
176
+ flags manager will be cleared, and then potentially re-detected based on
177
+ `use_browser_exe` and `browser_name_in_system`.
178
+ browser_name_in_system (Optional[str]): The common name of the browser (e.g., "Chrome", "Edge").
179
+ Used in conjunction with `use_browser_exe` to automatically detect the browser executable path.
180
+ This parameter only takes effect if `use_browser_exe` is explicitly `True` or `False`.
181
+ If `None`, no automatic detection based on name will occur through this method call.
182
+ use_browser_exe (Optional[bool]): Controls the automatic detection of the browser executable.
183
+ If `True` (and `browser_name_in_system` is provided), the browser executable path
184
+ will be automatically detected if `browser_exe` is `None`.
185
+ If `False` (and `browser_name_in_system` is provided), any existing `browser_exe`
186
+ path in the flags manager will be cleared.
187
+ If `None`, the current `use_browser_exe` state is maintained for the `_detect_browser_exe` logic.
188
+ start_page_url (str): The URL that the browser will attempt to navigate to
189
+ immediately after starting. Defaults to an empty string.
190
+ window_rect (Optional[WindowRect]): The initial window size and position settings.
191
+ If `None`, it defaults to a new `WindowRect()` instance, effectively resetting
192
+ to the browser's default window behavior.
193
+ trio_tokens_limit (Union[int, float]): The maximum number of concurrent synchronous
194
+ WebDriver operations allowed by the Trio capacity limiter. Defaults to 40.
195
+ """
196
+
197
+ ...
198
+
199
+ def restart_webdriver(
200
+ self,
201
+ flags: Optional[Union["BlinkFlags", _any_flags_mapping]] = None,
202
+ browser_exe: Optional[Union[str, pathlib.Path]] = None,
203
+ browser_name_in_system: Optional[str] = None,
204
+ use_browser_exe: Optional[bool] = None,
205
+ start_page_url: Optional[str] = None,
206
+ window_rect: Optional[WindowRect] = None,
207
+ trio_tokens_limit: Optional[Union[int, float]] = None,
208
+ ):
209
+ """
210
+ Restarts the WebDriver and browser session gracefully.
211
+
212
+ Performs a clean restart by first closing the existing WebDriver session and browser
213
+ (using `close_webdriver`), and then initiating a new session (using `start_webdriver`)
214
+ with potentially updated settings. If settings arguments are provided, they override
215
+ the existing settings for the new session; otherwise, the current settings are used.
216
+
217
+ Args:
218
+ flags (Optional[Union[BlinkFlags, Mapping[str, Any]]]): Override flags for the new session.
219
+ If provided, these flags will be applied. If `None`, current settings are used.
220
+ browser_exe (Optional[Union[str, pathlib.Path]]): Override browser executable for the new session.
221
+ If provided, this path will be used. If `None`, current settings are used.
222
+ browser_name_in_system (Optional[str]): Override browser name for auto-detection for the new session.
223
+ Only takes effect if `use_browser_exe` is also provided. If `None`, current settings are used.
224
+ use_browser_exe (Optional[bool]): Override auto-detection behavior for the new session.
225
+ If provided, this boolean determines if the browser executable is auto-detected.
226
+ If `None`, current settings are used.
227
+ start_page_url (Optional[str]): Override start page URL for the new session.
228
+ If provided, this URL will be used. If `None`, current setting is used.
229
+ window_rect (Optional[WindowRect]): Override window rectangle for the new session.
230
+ If provided, these dimensions will be used. If `None`, current settings are used.
231
+ trio_tokens_limit (Optional[Union[int, float]]): Override Trio token limit for the new session.
232
+ If provided, this limit will be used. If `None`, current setting is used.
233
+ """
234
+
235
+ ...
236
+
237
+ async def set_start_page_url(self, start_page_url: str):
238
+ """
239
+ Sets the URL that the browser will open upon starting.
240
+
241
+ Args:
242
+ start_page_url (str): The URL to set as the start page.
243
+ """
244
+
245
+ ...
246
+
247
+ def start_webdriver(
248
+ self,
249
+ flags: Optional[Union["BlinkFlags", _any_flags_mapping]] = None,
250
+ browser_exe: Optional[Union[str, pathlib.Path]] = None,
251
+ browser_name_in_system: Optional[str] = None,
252
+ use_browser_exe: Optional[bool] = None,
253
+ start_page_url: Optional[str] = None,
254
+ window_rect: Optional[WindowRect] = None,
255
+ trio_tokens_limit: Optional[Union[int, float]] = None,
256
+ ):
257
+ """
258
+ Starts the WebDriver service and the browser session.
259
+
260
+ Initializes and starts the WebDriver instance and the associated browser process.
261
+ It first updates settings based on provided parameters (if the driver is not already running),
262
+ checks if a browser process needs to be started, starts it if necessary using Popen,
263
+ waits for it to become active, and then creates the WebDriver client instance (`self.driver`).
264
+
265
+ Args:
266
+ flags (Optional[Union[BlinkFlags, Mapping[str, Any]]]): Override flags for this start.
267
+ If provided, these flags will be applied. If `None`, current settings are used.
268
+ browser_exe (Optional[Union[str, pathlib.Path]]): Override browser executable path for this start.
269
+ If provided, this path will be used. If `None`, current settings are used.
270
+ browser_name_in_system (Optional[str]): Override browser name for auto-detection for this start.
271
+ Only takes effect if `use_browser_exe` is also provided. If `None`, current settings are used.
272
+ use_browser_exe (Optional[bool]): Override auto-detection behavior for this start.
273
+ If provided, this boolean determines if the browser executable is auto-detected.
274
+ If `None`, current settings are used.
275
+ start_page_url (Optional[str]): Override start page URL for this start.
276
+ If provided, this URL will be used. If `None`, current setting is used.
277
+ window_rect (Optional[WindowRect]): Override window rectangle for this start.
278
+ If provided, these dimensions will be used. If `None`, current settings are used.
279
+ trio_tokens_limit (Optional[Union[int, float]]): Override Trio token limit for this start.
280
+ If provided, this limit will be used. If `None`, current setting is used.
281
+ """
282
+
283
+ ...
284
+
285
+ def update_settings(
286
+ self,
287
+ flags: Optional[Union["BlinkFlags", _any_flags_mapping]] = None,
288
+ browser_exe: Optional[Union[str, pathlib.Path]] = None,
289
+ browser_name_in_system: Optional[str] = None,
290
+ use_browser_exe: Optional[bool] = None,
291
+ start_page_url: Optional[str] = None,
292
+ window_rect: Optional[WindowRect] = None,
293
+ trio_tokens_limit: Optional[Union[int, float]] = None,
294
+ ):
295
+ """
296
+ Updates various browser settings selectively without resetting others.
297
+
298
+ This method allows for dynamic updating of browser settings. Only the settings
299
+ for which a non-None value is provided will be updated. Settings passed as `None`
300
+ will retain their current values. This method can be called whether the browser
301
+ is active or not, but some changes might only take effect after the browser is
302
+ restarted.
303
+
304
+ Args:
305
+ flags (Optional[Union[BlinkFlags, Mapping[str, Any]]]): New browser flags to update.
306
+ If provided, these flags will be merged with or overwrite existing flags
307
+ within the flags manager. If `None`, existing flags remain unchanged.
308
+ browser_exe (Optional[Union[str, pathlib.Path]]): The new path to the browser executable.
309
+ If provided, this path will be set in the flags manager. If `None`, the
310
+ current browser executable path remains unchanged.
311
+ browser_name_in_system (Optional[str]): The common name of the browser (e.g., "Chrome", "Edge").
312
+ Used in conjunction with `use_browser_exe` to automatically detect the browser executable path.
313
+ This parameter only takes effect if `use_browser_exe` is explicitly provided.
314
+ If `None`, no automatic detection based on name will occur through this method call.
315
+ use_browser_exe (Optional[bool]): Controls the automatic detection of the browser executable.
316
+ If `True` (and `browser_name_in_system` is provided), the browser executable path
317
+ will be automatically detected if `browser_exe` is `None`.
318
+ If `False` (and `browser_name_in_system` is provided), any existing `browser_exe`
319
+ path in the flags manager will be cleared.
320
+ If `None`, the current `use_browser_exe` state is maintained for the `_detect_browser_exe` logic.
321
+ start_page_url (Optional[str]): The new URL that the browser will attempt to navigate to
322
+ immediately after starting. If `None`, the current start page URL remains unchanged.
323
+ window_rect (Optional[WindowRect]): The new window size and position settings.
324
+ If `None`, the current window rectangle settings remain unchanged.
325
+ trio_tokens_limit (Optional[Union[int, float]]): The new maximum number of concurrent
326
+ asynchronous operations allowed by the Trio capacity limiter. If `None`, the
327
+ current limit remains unchanged.
328
+ """
329
+
330
+ ...