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,394 @@
|
|
|
1
|
+
import pathlib
|
|
2
|
+
from selenium import webdriver
|
|
3
|
+
from osn_selenium.types import WindowRect
|
|
4
|
+
from selenium.webdriver.chrome.service import Service
|
|
5
|
+
from typing import (
|
|
6
|
+
Optional,
|
|
7
|
+
Type,
|
|
8
|
+
Union,
|
|
9
|
+
cast
|
|
10
|
+
)
|
|
11
|
+
from osn_selenium.dev_tools.manager import DevToolsSettings
|
|
12
|
+
from osn_selenium.webdrivers.types import _any_flags_mapping
|
|
13
|
+
from osn_selenium.captcha_workers import (
|
|
14
|
+
CaptchaWorkerSettings
|
|
15
|
+
)
|
|
16
|
+
from osn_selenium.webdrivers.Blink.webdriver import BlinkWebDriver
|
|
17
|
+
from osn_selenium.webdrivers.Chrome.flags import (
|
|
18
|
+
ChromeFlags,
|
|
19
|
+
ChromeFlagsManager
|
|
20
|
+
)
|
|
21
|
+
from osn_selenium.webdrivers.BaseDriver.trio_wrapper import (
|
|
22
|
+
TrioBrowserWebDriverWrapper
|
|
23
|
+
)
|
|
24
|
+
from osn_selenium.webdrivers.Chrome.protocols import (
|
|
25
|
+
TrioChromeWebDriverWrapperProtocol
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class ChromeWebDriver(BlinkWebDriver):
|
|
30
|
+
"""
|
|
31
|
+
Manages a Chrome Browser session using Selenium WebDriver.
|
|
32
|
+
|
|
33
|
+
This class specializes BlinkWebDriver for Chrome Browser. It sets up and manages
|
|
34
|
+
the lifecycle of a Chrome Browser instance controlled by Selenium WebDriver,
|
|
35
|
+
including starting the browser with specific options, handling sessions, and managing browser processes.
|
|
36
|
+
Chrome Browser is based on Chromium, so it uses ChromeOptions and ChromeDriver.
|
|
37
|
+
|
|
38
|
+
Attributes:
|
|
39
|
+
_window_rect (Optional[WindowRect]): The window size and position settings.
|
|
40
|
+
_js_scripts (dict[str, str]): A dictionary of pre-loaded JavaScript scripts.
|
|
41
|
+
_webdriver_path (str): The file path to the WebDriver executable.
|
|
42
|
+
_webdriver_flags_manager (ChromeFlagsManager): The manager for browser flags and options.
|
|
43
|
+
_driver (Optional[webdriver.Chrome]): The active Selenium WebDriver instance.
|
|
44
|
+
_base_implicitly_wait (int): The default implicit wait time in seconds.
|
|
45
|
+
_base_page_load_timeout (int): The default page load timeout in seconds.
|
|
46
|
+
_base_script_timeout (int): The default script timeout in seconds.
|
|
47
|
+
_captcha_workers (list[CaptchaWorkerSettings]): A list of configured captcha worker settings.
|
|
48
|
+
_is_active (bool): A flag indicating if the browser process is active.
|
|
49
|
+
trio_capacity_limiter (trio.CapacityLimiter): A capacity limiter for controlling concurrent async operations.
|
|
50
|
+
dev_tools (DevTools): An interface for interacting with the browser's DevTools protocol.
|
|
51
|
+
_console_encoding (str): The encoding of the system console.
|
|
52
|
+
_ip_pattern (re.Pattern): A compiled regex pattern to match IP addresses and ports.
|
|
53
|
+
"""
|
|
54
|
+
|
|
55
|
+
def __init__(
|
|
56
|
+
self,
|
|
57
|
+
webdriver_path: str,
|
|
58
|
+
flags_manager_type: Type[ChromeFlagsManager] = ChromeFlagsManager,
|
|
59
|
+
use_browser_exe: bool = True,
|
|
60
|
+
browser_name_in_system: str = "Chrome",
|
|
61
|
+
browser_exe: Optional[Union[str, pathlib.Path]] = None,
|
|
62
|
+
flags: Optional[ChromeFlags] = None,
|
|
63
|
+
start_page_url: str = "https://www.chrome.com",
|
|
64
|
+
implicitly_wait: int = 5,
|
|
65
|
+
page_load_timeout: int = 5,
|
|
66
|
+
script_timeout: int = 5,
|
|
67
|
+
window_rect: Optional[WindowRect] = None,
|
|
68
|
+
trio_tokens_limit: Union[int, float] = 40,
|
|
69
|
+
captcha_workers: Optional[list[CaptchaWorkerSettings]] = None,
|
|
70
|
+
devtools_settings: Optional[DevToolsSettings] = None,
|
|
71
|
+
):
|
|
72
|
+
"""
|
|
73
|
+
Initializes a ChromeWebDriver instance.
|
|
74
|
+
|
|
75
|
+
This constructor prepares the Chrome Browser for automation by setting up
|
|
76
|
+
its executable path, WebDriver path, browser flags, and other operational
|
|
77
|
+
settings. It leverages the `BlinkWebDriver` base class for common Chromium-based
|
|
78
|
+
browser functionalities.
|
|
79
|
+
|
|
80
|
+
Args:
|
|
81
|
+
webdriver_path (str): The file path to the ChromeDriver executable.
|
|
82
|
+
flags_manager_type (Type[ChromeFlagsManager]): The type of flags manager
|
|
83
|
+
to use for configuring Chrome Browser-specific command-line arguments.
|
|
84
|
+
Defaults to `ChromeFlagsManager`.
|
|
85
|
+
use_browser_exe (bool): If True, the browser executable path will be
|
|
86
|
+
automatically determined based on `browser_name_in_system` if `browser_exe`
|
|
87
|
+
is not explicitly provided. If False, `browser_exe` must be None.
|
|
88
|
+
Defaults to True.
|
|
89
|
+
browser_name_in_system (str): The common name of the Chrome Browser
|
|
90
|
+
executable in the system (e.g., "Chrome"). Used to auto-detect `browser_exe`.
|
|
91
|
+
Defaults to "Chrome".
|
|
92
|
+
browser_exe (Optional[Union[str, pathlib.Path]]): The explicit path to the
|
|
93
|
+
Chrome Browser executable. If `use_browser_exe` is True and this is None,
|
|
94
|
+
it will attempt to find the browser automatically. If `use_browser_exe`
|
|
95
|
+
is False, this must be None.
|
|
96
|
+
flags (Optional[ChromeFlags]): An object containing specific flags or options
|
|
97
|
+
to pass to the Chrome Browser process.
|
|
98
|
+
start_page_url (str): The URL to load when the browser session starts.
|
|
99
|
+
Defaults to "https://www.chrome.com".
|
|
100
|
+
implicitly_wait (int): The default implicit wait time in seconds for the WebDriver.
|
|
101
|
+
Defaults to 5 seconds.
|
|
102
|
+
page_load_timeout (int): The default timeout in seconds for page loading.
|
|
103
|
+
Defaults to 5 seconds.
|
|
104
|
+
script_timeout (int): The default timeout in seconds for asynchronous JavaScript execution.
|
|
105
|
+
Defaults to 5 seconds.
|
|
106
|
+
window_rect (Optional[WindowRect]): An object specifying the initial window
|
|
107
|
+
position and size.
|
|
108
|
+
trio_tokens_limit (Union[int, float]): The maximum number of concurrent
|
|
109
|
+
asynchronous operations allowed by the Trio capacity limiter. Defaults to 40.
|
|
110
|
+
captcha_workers (Optional[Sequence[CaptchaWorkerSettings]]): A sequence of
|
|
111
|
+
settings for captcha detection and solving functions.
|
|
112
|
+
devtools_settings (Optional[DevToolsSettings]): Settings for configuring the
|
|
113
|
+
Chrome DevTools Protocol (CDP) interface.
|
|
114
|
+
"""
|
|
115
|
+
|
|
116
|
+
super().__init__(
|
|
117
|
+
browser_exe=browser_exe,
|
|
118
|
+
browser_name_in_system=browser_name_in_system,
|
|
119
|
+
use_browser_exe=use_browser_exe,
|
|
120
|
+
webdriver_path=webdriver_path,
|
|
121
|
+
flags_manager_type=flags_manager_type,
|
|
122
|
+
flags=flags,
|
|
123
|
+
start_page_url=start_page_url,
|
|
124
|
+
implicitly_wait=implicitly_wait,
|
|
125
|
+
page_load_timeout=page_load_timeout,
|
|
126
|
+
script_timeout=script_timeout,
|
|
127
|
+
window_rect=window_rect,
|
|
128
|
+
trio_tokens_limit=trio_tokens_limit,
|
|
129
|
+
captcha_workers=captcha_workers,
|
|
130
|
+
devtools_settings=devtools_settings,
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
def _create_driver(self):
|
|
134
|
+
"""
|
|
135
|
+
Creates the Chrome webdriver instance.
|
|
136
|
+
|
|
137
|
+
This method initializes and sets up the Selenium Chrome WebDriver using ChromeDriver with configured options and service.
|
|
138
|
+
It also sets the window position, size, implicit wait time, and page load timeout.
|
|
139
|
+
"""
|
|
140
|
+
|
|
141
|
+
webdriver_options = self._webdriver_flags_manager.options
|
|
142
|
+
webdriver_service = Service(
|
|
143
|
+
executable_path=self._webdriver_path,
|
|
144
|
+
port=self.debugging_port if self.browser_exe is None else 0,
|
|
145
|
+
service_args=self._webdriver_flags_manager.start_args
|
|
146
|
+
if self.browser_exe is None
|
|
147
|
+
else None
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
self._driver = webdriver.Chrome(options=webdriver_options, service=webdriver_service)
|
|
151
|
+
|
|
152
|
+
if self._window_rect is not None:
|
|
153
|
+
self.set_window_rect(self._window_rect)
|
|
154
|
+
|
|
155
|
+
self.set_driver_timeouts(
|
|
156
|
+
page_load_timeout=self._base_page_load_timeout,
|
|
157
|
+
implicit_wait_timeout=self._base_implicitly_wait,
|
|
158
|
+
script_timeout=self._base_implicitly_wait,
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
@property
|
|
162
|
+
def driver(self) -> Optional[webdriver.Chrome]:
|
|
163
|
+
"""
|
|
164
|
+
Gets the underlying Selenium WebDriver instance associated with this object.
|
|
165
|
+
|
|
166
|
+
This property provides direct access to the WebDriver object (e.g., Chrome)
|
|
167
|
+
that is being controlled, allowing for direct Selenium operations if needed.
|
|
168
|
+
|
|
169
|
+
Returns:
|
|
170
|
+
Optional[webdriver.Chrome]:
|
|
171
|
+
The active WebDriver instance, or None if no driver is currently set or active.
|
|
172
|
+
"""
|
|
173
|
+
|
|
174
|
+
return super().driver
|
|
175
|
+
|
|
176
|
+
def reset_settings(
|
|
177
|
+
self,
|
|
178
|
+
flags: Optional[Union[ChromeFlags, _any_flags_mapping]] = None,
|
|
179
|
+
browser_exe: Optional[Union[str, pathlib.Path]] = None,
|
|
180
|
+
browser_name_in_system: Optional[str] = None,
|
|
181
|
+
use_browser_exe: Optional[bool] = None,
|
|
182
|
+
start_page_url: str = "",
|
|
183
|
+
window_rect: Optional[WindowRect] = None,
|
|
184
|
+
trio_tokens_limit: Union[int, float] = 40,
|
|
185
|
+
):
|
|
186
|
+
"""
|
|
187
|
+
Resets various configurable browser settings to their specified or default values.
|
|
188
|
+
|
|
189
|
+
This method allows for reconfiguring the WebDriver's operational parameters,
|
|
190
|
+
such as browser flags, executable path, start URL, window dimensions, and
|
|
191
|
+
concurrency limits. It is crucial that the browser session is *not* active
|
|
192
|
+
when this method is called; otherwise, a warning will be issued, and no changes
|
|
193
|
+
will be applied.
|
|
194
|
+
|
|
195
|
+
Args:
|
|
196
|
+
flags (Optional[Union[ChromeFlags, Mapping[str, Any]]]): New browser flags to apply.
|
|
197
|
+
If provided, existing flags are cleared and replaced with these.
|
|
198
|
+
If `None`, all custom flags are cleared, and the browser will start with default flags.
|
|
199
|
+
browser_exe (Optional[Union[str, pathlib.Path]]): The explicit path to the browser executable.
|
|
200
|
+
If provided, this path will be used. If `None`, the executable path managed by the
|
|
201
|
+
flags manager will be cleared, and then potentially re-detected based on
|
|
202
|
+
`use_browser_exe` and `browser_name_in_system`.
|
|
203
|
+
browser_name_in_system (Optional[str]): The common name of the browser (e.g., "Chrome", "Edge").
|
|
204
|
+
Used in conjunction with `use_browser_exe` to automatically detect the browser executable path.
|
|
205
|
+
This parameter only takes effect if `use_browser_exe` is explicitly `True` or `False`.
|
|
206
|
+
If `None`, no automatic detection based on name will occur through this method call.
|
|
207
|
+
use_browser_exe (Optional[bool]): Controls the automatic detection of the browser executable.
|
|
208
|
+
If `True` (and `browser_name_in_system` is provided), the browser executable path
|
|
209
|
+
will be automatically detected if `browser_exe` is `None`.
|
|
210
|
+
If `False` (and `browser_name_in_system` is provided), any existing `browser_exe`
|
|
211
|
+
path in the flags manager will be cleared.
|
|
212
|
+
If `None`, the current `use_browser_exe` state is maintained for the `_detect_browser_exe` logic.
|
|
213
|
+
start_page_url (str): The URL that the browser will attempt to navigate to
|
|
214
|
+
immediately after starting. Defaults to an empty string.
|
|
215
|
+
window_rect (Optional[WindowRect]): The initial window size and position settings.
|
|
216
|
+
If `None`, it defaults to a new `WindowRect()` instance, effectively resetting
|
|
217
|
+
to the browser's default window behavior.
|
|
218
|
+
trio_tokens_limit (Union[int, float]): The maximum number of concurrent synchronous
|
|
219
|
+
WebDriver operations allowed by the Trio capacity limiter. Defaults to 40.
|
|
220
|
+
"""
|
|
221
|
+
|
|
222
|
+
super().reset_settings(
|
|
223
|
+
flags=flags,
|
|
224
|
+
browser_exe=browser_exe,
|
|
225
|
+
browser_name_in_system=browser_name_in_system,
|
|
226
|
+
use_browser_exe=use_browser_exe,
|
|
227
|
+
start_page_url=start_page_url,
|
|
228
|
+
window_rect=window_rect,
|
|
229
|
+
trio_tokens_limit=trio_tokens_limit,
|
|
230
|
+
)
|
|
231
|
+
|
|
232
|
+
def restart_webdriver(
|
|
233
|
+
self,
|
|
234
|
+
flags: Optional[Union[ChromeFlags, _any_flags_mapping]] = None,
|
|
235
|
+
browser_exe: Optional[Union[str, pathlib.Path]] = None,
|
|
236
|
+
browser_name_in_system: Optional[str] = None,
|
|
237
|
+
use_browser_exe: Optional[bool] = None,
|
|
238
|
+
start_page_url: Optional[str] = None,
|
|
239
|
+
window_rect: Optional[WindowRect] = None,
|
|
240
|
+
trio_tokens_limit: Optional[Union[int, float]] = None,
|
|
241
|
+
):
|
|
242
|
+
"""
|
|
243
|
+
Restarts the WebDriver and browser session gracefully.
|
|
244
|
+
|
|
245
|
+
Performs a clean restart by first closing the existing WebDriver session and browser
|
|
246
|
+
(using `close_webdriver`), and then initiating a new session (using `start_webdriver`)
|
|
247
|
+
with potentially updated settings. If settings arguments are provided, they override
|
|
248
|
+
the existing settings for the new session; otherwise, the current settings are used.
|
|
249
|
+
|
|
250
|
+
Args:
|
|
251
|
+
flags (Optional[Union[ChromeFlags, Mapping[str, Any]]]): Override flags for the new session.
|
|
252
|
+
If provided, these flags will be applied. If `None`, current settings are used.
|
|
253
|
+
browser_exe (Optional[Union[str, pathlib.Path]]): Override browser executable for the new session.
|
|
254
|
+
If provided, this path will be used. If `None`, current settings are used.
|
|
255
|
+
browser_name_in_system (Optional[str]): Override browser name for auto-detection for the new session.
|
|
256
|
+
Only takes effect if `use_browser_exe` is also provided. If `None`, current settings are used.
|
|
257
|
+
use_browser_exe (Optional[bool]): Override auto-detection behavior for the new session.
|
|
258
|
+
If provided, this boolean determines if the browser executable is auto-detected.
|
|
259
|
+
If `None`, current settings are used.
|
|
260
|
+
start_page_url (Optional[str]): Override start page URL for the new session.
|
|
261
|
+
If provided, this URL will be used. If `None`, current setting is used.
|
|
262
|
+
window_rect (Optional[WindowRect]): Override window rectangle for the new session.
|
|
263
|
+
If provided, these dimensions will be used. If `None`, current settings are used.
|
|
264
|
+
trio_tokens_limit (Optional[Union[int, float]]): Override Trio token limit for the new session.
|
|
265
|
+
If provided, this limit will be used. If `None`, current setting is used.
|
|
266
|
+
"""
|
|
267
|
+
|
|
268
|
+
super().restart_webdriver(
|
|
269
|
+
flags=flags,
|
|
270
|
+
browser_exe=browser_exe,
|
|
271
|
+
browser_name_in_system=browser_name_in_system,
|
|
272
|
+
use_browser_exe=use_browser_exe,
|
|
273
|
+
start_page_url=start_page_url,
|
|
274
|
+
window_rect=window_rect,
|
|
275
|
+
trio_tokens_limit=trio_tokens_limit,
|
|
276
|
+
)
|
|
277
|
+
|
|
278
|
+
def start_webdriver(
|
|
279
|
+
self,
|
|
280
|
+
flags: Optional[Union[ChromeFlags, _any_flags_mapping]] = None,
|
|
281
|
+
browser_exe: Optional[Union[str, pathlib.Path]] = None,
|
|
282
|
+
browser_name_in_system: Optional[str] = None,
|
|
283
|
+
use_browser_exe: Optional[bool] = None,
|
|
284
|
+
start_page_url: Optional[str] = None,
|
|
285
|
+
window_rect: Optional[WindowRect] = None,
|
|
286
|
+
trio_tokens_limit: Optional[Union[int, float]] = None,
|
|
287
|
+
):
|
|
288
|
+
"""
|
|
289
|
+
Starts the WebDriver service and the browser session.
|
|
290
|
+
|
|
291
|
+
Initializes and starts the WebDriver instance and the associated browser process.
|
|
292
|
+
It first updates settings based on provided parameters (if the driver is not already running),
|
|
293
|
+
checks if a browser process needs to be started, starts it if necessary using Popen,
|
|
294
|
+
waits for it to become active, and then creates the WebDriver client instance (`self.driver`).
|
|
295
|
+
|
|
296
|
+
Args:
|
|
297
|
+
flags (Optional[Union[ChromeFlags, Mapping[str, Any]]]): Override flags for this start.
|
|
298
|
+
If provided, these flags will be applied. If `None`, current settings are used.
|
|
299
|
+
browser_exe (Optional[Union[str, pathlib.Path]]): Override browser executable path for this start.
|
|
300
|
+
If provided, this path will be used. If `None`, current settings are used.
|
|
301
|
+
browser_name_in_system (Optional[str]): Override browser name for auto-detection for this start.
|
|
302
|
+
Only takes effect if `use_browser_exe` is also provided. If `None`, current settings are used.
|
|
303
|
+
use_browser_exe (Optional[bool]): Override auto-detection behavior for this start.
|
|
304
|
+
If provided, this boolean determines if the browser executable is auto-detected.
|
|
305
|
+
If `None`, current settings are used.
|
|
306
|
+
start_page_url (Optional[str]): Override start page URL for this start.
|
|
307
|
+
If provided, this URL will be used. If `None`, current setting is used.
|
|
308
|
+
window_rect (Optional[WindowRect]): Override window rectangle for this start.
|
|
309
|
+
If provided, these dimensions will be used. If `None`, current settings are used.
|
|
310
|
+
trio_tokens_limit (Optional[Union[int, float]]): Override Trio token limit for this start.
|
|
311
|
+
If provided, this limit will be used. If `None`, current setting is used.
|
|
312
|
+
"""
|
|
313
|
+
|
|
314
|
+
super().start_webdriver(
|
|
315
|
+
flags=flags,
|
|
316
|
+
browser_exe=browser_exe,
|
|
317
|
+
browser_name_in_system=browser_name_in_system,
|
|
318
|
+
use_browser_exe=use_browser_exe,
|
|
319
|
+
start_page_url=start_page_url,
|
|
320
|
+
window_rect=window_rect,
|
|
321
|
+
trio_tokens_limit=trio_tokens_limit,
|
|
322
|
+
)
|
|
323
|
+
|
|
324
|
+
def to_wrapper(self) -> TrioChromeWebDriverWrapperProtocol:
|
|
325
|
+
"""
|
|
326
|
+
Creates a TrioBrowserWebDriverWrapper instance for asynchronous operations with Trio.
|
|
327
|
+
|
|
328
|
+
Wraps the ...WebDriver instance in a TrioBrowserWebDriverWrapper, which allows for running WebDriver
|
|
329
|
+
commands in a non-blocking manner within a Trio asynchronous context. This is essential for
|
|
330
|
+
integrating Selenium WebDriver with asynchronous frameworks like Trio.
|
|
331
|
+
|
|
332
|
+
Returns:
|
|
333
|
+
TrioChromeWebDriverWrapperProtocol: A TrioBrowserWebDriverWrapper instance wrapping this BrowserWebDriver.
|
|
334
|
+
"""
|
|
335
|
+
|
|
336
|
+
return cast(
|
|
337
|
+
TrioChromeWebDriverWrapperProtocol,
|
|
338
|
+
TrioBrowserWebDriverWrapper(_webdriver=self)
|
|
339
|
+
)
|
|
340
|
+
|
|
341
|
+
def update_settings(
|
|
342
|
+
self,
|
|
343
|
+
flags: Optional[Union[ChromeFlags, _any_flags_mapping]] = None,
|
|
344
|
+
browser_exe: Optional[Union[str, pathlib.Path]] = None,
|
|
345
|
+
browser_name_in_system: Optional[str] = None,
|
|
346
|
+
use_browser_exe: Optional[bool] = None,
|
|
347
|
+
start_page_url: Optional[str] = None,
|
|
348
|
+
window_rect: Optional[WindowRect] = None,
|
|
349
|
+
trio_tokens_limit: Optional[Union[int, float]] = None,
|
|
350
|
+
):
|
|
351
|
+
"""
|
|
352
|
+
Updates various browser settings selectively without resetting others.
|
|
353
|
+
|
|
354
|
+
This method allows for dynamic updating of browser settings. Only the settings
|
|
355
|
+
for which a non-None value is provided will be updated. Settings passed as `None`
|
|
356
|
+
will retain their current values. This method can be called whether the browser
|
|
357
|
+
is active or not, but some changes might only take effect after the browser is
|
|
358
|
+
restarted.
|
|
359
|
+
|
|
360
|
+
Args:
|
|
361
|
+
flags (Optional[Union[ChromeFlags, Mapping[str, Any]]]): New browser flags to update.
|
|
362
|
+
If provided, these flags will be merged with or overwrite existing flags
|
|
363
|
+
within the flags manager. If `None`, existing flags remain unchanged.
|
|
364
|
+
browser_exe (Optional[Union[str, pathlib.Path]]): The new path to the browser executable.
|
|
365
|
+
If provided, this path will be set in the flags manager. If `None`, the
|
|
366
|
+
current browser executable path remains unchanged.
|
|
367
|
+
browser_name_in_system (Optional[str]): The common name of the browser (e.g., "Chrome", "Edge").
|
|
368
|
+
Used in conjunction with `use_browser_exe` to automatically detect the browser executable path.
|
|
369
|
+
This parameter only takes effect if `use_browser_exe` is explicitly provided.
|
|
370
|
+
If `None`, no automatic detection based on name will occur through this method call.
|
|
371
|
+
use_browser_exe (Optional[bool]): Controls the automatic detection of the browser executable.
|
|
372
|
+
If `True` (and `browser_name_in_system` is provided), the browser executable path
|
|
373
|
+
will be automatically detected if `browser_exe` is `None`.
|
|
374
|
+
If `False` (and `browser_name_in_system` is provided), any existing `browser_exe`
|
|
375
|
+
path in the flags manager will be cleared.
|
|
376
|
+
If `None`, the current `use_browser_exe` state is maintained for the `_detect_browser_exe` logic.
|
|
377
|
+
start_page_url (Optional[str]): The new URL that the browser will attempt to navigate to
|
|
378
|
+
immediately after starting. If `None`, the current start page URL remains unchanged.
|
|
379
|
+
window_rect (Optional[WindowRect]): The new window size and position settings.
|
|
380
|
+
If `None`, the current window rectangle settings remain unchanged.
|
|
381
|
+
trio_tokens_limit (Optional[Union[int, float]]): The new maximum number of concurrent
|
|
382
|
+
asynchronous operations allowed by the Trio capacity limiter. If `None`, the
|
|
383
|
+
current limit remains unchanged.
|
|
384
|
+
"""
|
|
385
|
+
|
|
386
|
+
super().update_settings(
|
|
387
|
+
flags=flags,
|
|
388
|
+
browser_exe=browser_exe,
|
|
389
|
+
browser_name_in_system=browser_name_in_system,
|
|
390
|
+
use_browser_exe=use_browser_exe,
|
|
391
|
+
start_page_url=start_page_url,
|
|
392
|
+
window_rect=window_rect,
|
|
393
|
+
trio_tokens_limit=trio_tokens_limit,
|
|
394
|
+
)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import pathlib
|
|
2
|
+
from typing import (
|
|
3
|
+
Optional,
|
|
4
|
+
TypedDict,
|
|
5
|
+
Union
|
|
6
|
+
)
|
|
7
|
+
from selenium.webdriver.chrome.options import Options
|
|
8
|
+
from osn_selenium.webdrivers.types import (
|
|
9
|
+
FlagDefinition,
|
|
10
|
+
FlagType
|
|
11
|
+
)
|
|
12
|
+
from osn_selenium.webdrivers.Blink.flags import (
|
|
13
|
+
BlinkArguments,
|
|
14
|
+
BlinkAttributes,
|
|
15
|
+
BlinkExperimentalOptions,
|
|
16
|
+
BlinkFeatures,
|
|
17
|
+
BlinkFlagsManager
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class EdgeFlagsManager(BlinkFlagsManager):
|
|
22
|
+
"""
|
|
23
|
+
Manages Edge Browser-specific options for Selenium WebDriver.
|
|
24
|
+
|
|
25
|
+
This class extends BrowserOptionsManager to provide specific configurations
|
|
26
|
+
for Edge Browser options, such as experimental options and arguments.
|
|
27
|
+
|
|
28
|
+
Attributes:
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
def __init__(
|
|
32
|
+
self,
|
|
33
|
+
browser_exe: Optional[Union[str, pathlib.Path]] = None,
|
|
34
|
+
start_page_url: Optional[str] = None,
|
|
35
|
+
flags_types: Optional[dict[str, FlagType]] = None,
|
|
36
|
+
flags_definitions: Optional[dict[str, FlagDefinition]] = None
|
|
37
|
+
):
|
|
38
|
+
"""
|
|
39
|
+
Initializes EdgeOptionsManager.
|
|
40
|
+
|
|
41
|
+
Sets up the Edge Browser options manager with specific option configurations for
|
|
42
|
+
debugging port, user agent, proxy, and BiDi protocol.
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
yandex_flags_types = {}
|
|
46
|
+
|
|
47
|
+
if flags_types is not None:
|
|
48
|
+
yandex_flags_types.update(flags_types)
|
|
49
|
+
|
|
50
|
+
yandex_flags_definitions = {}
|
|
51
|
+
|
|
52
|
+
if flags_definitions is not None:
|
|
53
|
+
yandex_flags_definitions.update(flags_definitions)
|
|
54
|
+
|
|
55
|
+
super().__init__(
|
|
56
|
+
browser_exe=browser_exe,
|
|
57
|
+
start_page_url=start_page_url,
|
|
58
|
+
flags_types=yandex_flags_types,
|
|
59
|
+
flags_definitions=yandex_flags_definitions,
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
def _renew_webdriver_options(self) -> Options:
|
|
63
|
+
"""
|
|
64
|
+
Creates and returns a new Options object.
|
|
65
|
+
|
|
66
|
+
Returns a fresh instance of `webdriver.EdgeOptions`, as Edge Browser is based on Chromium,
|
|
67
|
+
allowing for a clean state of browser options to be configured.
|
|
68
|
+
|
|
69
|
+
Returns:
|
|
70
|
+
Options: A new Selenium Edge Browser options object, based on EdgeOptions.
|
|
71
|
+
"""
|
|
72
|
+
|
|
73
|
+
return Options()
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class EdgeAttributes(BlinkAttributes, total=False):
|
|
77
|
+
"""
|
|
78
|
+
Typed dictionary for WebDriver attributes specific to Edge browsers.
|
|
79
|
+
|
|
80
|
+
Attributes:
|
|
81
|
+
enable_bidi (Optional[bool]): Enables/disables BiDi (Bidirectional) protocol mapper.
|
|
82
|
+
"""
|
|
83
|
+
|
|
84
|
+
pass
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
class EdgeExperimentalOptions(BlinkExperimentalOptions, total=False):
|
|
88
|
+
"""
|
|
89
|
+
Typed dictionary for experimental options specific to Edge browsers.
|
|
90
|
+
|
|
91
|
+
Attributes:
|
|
92
|
+
debugger_address (Optional[str]): The address (IP:port) of the remote debugger.
|
|
93
|
+
"""
|
|
94
|
+
|
|
95
|
+
pass
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
class EdgeArguments(BlinkArguments, total=False):
|
|
99
|
+
"""
|
|
100
|
+
Typed dictionary for command-line arguments specific to Edge browsers.
|
|
101
|
+
|
|
102
|
+
Attributes:
|
|
103
|
+
se_downloads_enabled (bool): Enables/disables Selenium downloads.
|
|
104
|
+
headless_mode (bool): Runs the browser in headless mode (without a UI).
|
|
105
|
+
mute_audio (bool): Mutes audio output from the browser.
|
|
106
|
+
no_first_run (bool): Prevents the browser from showing the "first run" experience.
|
|
107
|
+
disable_background_timer_throttling (bool): Disables throttling of background timers.
|
|
108
|
+
disable_backgrounding_occluded_windows (bool): Prevents backgrounding of occluded windows.
|
|
109
|
+
disable_hang_monitor (bool): Disables the browser's hang monitor.
|
|
110
|
+
disable_ipc_flooding_protection (bool): Disables IPC flooding protection.
|
|
111
|
+
disable_renderer_backgrounding (bool): Prevents renderer processes from being backgrounded.
|
|
112
|
+
disable_back_forward_cache (bool): Disables the Back-Forward Cache.
|
|
113
|
+
disable_notifications (bool): Disables web notifications.
|
|
114
|
+
disable_popup_blocking (bool): Disables the built-in popup blocker.
|
|
115
|
+
disable_prompt_on_repost (bool): Disables the prompt when reposting form data.
|
|
116
|
+
disable_sync (bool): Disables browser synchronization features.
|
|
117
|
+
disable_background_networking (bool): Disables background network activity.
|
|
118
|
+
disable_breakpad (bool): Disables the crash reporter.
|
|
119
|
+
disable_component_update (bool): Disables component updates.
|
|
120
|
+
disable_domain_reliability (bool): Disables domain reliability monitoring.
|
|
121
|
+
disable_new_content_rendering_timeout (bool): Disables timeout for new content rendering.
|
|
122
|
+
disable_threaded_animation (bool): Disables threaded animation.
|
|
123
|
+
disable_threaded_scrolling (bool): Disables threaded scrolling.
|
|
124
|
+
disable_checker_imaging (bool): Disables checker imaging.
|
|
125
|
+
disable_image_animation_resync (bool): Disables image animation resynchronization.
|
|
126
|
+
disable_partial_raster (bool): Disables partial rasterization.
|
|
127
|
+
disable_skia_runtime_opts (bool): Disables Skia runtime optimizations.
|
|
128
|
+
disable_dev_shm_usage (bool): Disables the use of /dev/shm (important for Docker).
|
|
129
|
+
disable_gpu (bool): Disables GPU hardware acceleration.
|
|
130
|
+
aggressive_cache_discard (bool): Enables aggressive discarding of cached data.
|
|
131
|
+
allow_running_insecure_content (bool): Allows running insecure content on HTTPS pages.
|
|
132
|
+
no_process_per_site (bool): Runs all sites in a single process (less secure, but saves memory).
|
|
133
|
+
enable_precise_memory_info (bool): Enables precise memory information reporting.
|
|
134
|
+
use_fake_device_for_media_stream (bool): Uses a fake camera/microphone for media streams.
|
|
135
|
+
use_fake_ui_for_media_stream (bool): Uses a fake UI for media stream requests.
|
|
136
|
+
deny_permission_prompts (bool): Automatically denies all permission prompts.
|
|
137
|
+
disable_external_intent_requests (bool): Disables external intent requests.
|
|
138
|
+
noerrdialogs (bool): Suppresses error dialogs.
|
|
139
|
+
enable_automation (bool): Enables automation features.
|
|
140
|
+
test_type (bool): Sets the browser to test mode.
|
|
141
|
+
remote_debugging_pipe (bool): Uses a pipe for remote debugging instead of a port.
|
|
142
|
+
silent_debugger_extension_api (bool): Silences debugger extension API warnings.
|
|
143
|
+
enable_logging_stderr (bool): Enables logging to stderr.
|
|
144
|
+
password_store_basic (bool): Uses a basic password store.
|
|
145
|
+
use_mock_keychain (bool): Uses a mock keychain for testing.
|
|
146
|
+
enable_crash_reporter_for_testing (bool): Enables crash reporter for testing purposes.
|
|
147
|
+
metrics_recording_only (bool): Records metrics without sending them.
|
|
148
|
+
no_pings (bool): Disables sending pings.
|
|
149
|
+
allow_pre_commit_input (bool): Allows pre-commit input.
|
|
150
|
+
deterministic_mode (bool): Runs the browser in a more deterministic mode.
|
|
151
|
+
run_all_compositor_stages_before_draw (bool): Runs all compositor stages before drawing.
|
|
152
|
+
enable_begin_frame_control (bool): Enables begin frame control.
|
|
153
|
+
in_process_gpu (bool): Runs the GPU process in-process.
|
|
154
|
+
block_new_web_contents (bool): Blocks new web contents (e.g., pop-ups).
|
|
155
|
+
new_window (bool): Opens a new window instead of a new tab.
|
|
156
|
+
no_service_autorun (bool): Disables service autorun.
|
|
157
|
+
process_per_tab (bool): Runs each tab in its own process.
|
|
158
|
+
single_process (bool): Runs the browser in a single process (less stable).
|
|
159
|
+
no_sandbox (bool): Disables the sandbox (less secure, but can fix some issues).
|
|
160
|
+
user_agent (Optional[str]): Sets a custom user agent string.
|
|
161
|
+
user_data_dir (Optional[str]): Specifies the user data directory.
|
|
162
|
+
proxy_server (Optional[str]): Specifies a proxy server to use.
|
|
163
|
+
remote_debugging_port (Optional[int]): Specifies the remote debugging port.
|
|
164
|
+
remote_debugging_address (Optional[str]): Specifies the remote debugging address.
|
|
165
|
+
use_file_for_fake_video_capture (Optional[Union[str, pathlib.Path]]): Uses a file for fake video capture.
|
|
166
|
+
autoplay_policy (Optional[AutoplayPolicyType]): Sets the autoplay policy.
|
|
167
|
+
log_level (Optional[LogLevelType]): Sets the browser's log level.
|
|
168
|
+
use_gl (Optional[UseGLType]): Specifies the GL backend to use.
|
|
169
|
+
force_color_profile (Optional[str]): Forces a specific color profile.
|
|
170
|
+
"""
|
|
171
|
+
|
|
172
|
+
pass
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
class EdgeFlags(TypedDict, total=False):
|
|
176
|
+
"""
|
|
177
|
+
Typed dictionary representing a collection of all flag types for Edge browsers.
|
|
178
|
+
|
|
179
|
+
This combines arguments, experimental options, attributes, and Blink features
|
|
180
|
+
that are specific to Edge browsers.
|
|
181
|
+
|
|
182
|
+
Attributes:
|
|
183
|
+
argument (EdgeArguments): Command-line arguments for the Edge browser.
|
|
184
|
+
experimental_option (EdgeExperimentalOptions): Experimental options for WebDriver specific to Edge.
|
|
185
|
+
attribute (EdgeAttributes): WebDriver attributes specific to Edge.
|
|
186
|
+
blink_feature (BlinkFeatures): Blink-specific feature flags.
|
|
187
|
+
"""
|
|
188
|
+
|
|
189
|
+
argument: EdgeArguments
|
|
190
|
+
experimental_option: EdgeExperimentalOptions
|
|
191
|
+
attribute: EdgeAttributes
|
|
192
|
+
blink_feature: BlinkFeatures
|