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 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import trio
|
|
2
|
+
from osn_selenium.dev_tools.utils import (
|
|
3
|
+
TargetData,
|
|
4
|
+
log_exception
|
|
5
|
+
)
|
|
6
|
+
from typing import (
|
|
7
|
+
Any,
|
|
8
|
+
Literal,
|
|
9
|
+
Sequence,
|
|
10
|
+
TYPE_CHECKING,
|
|
11
|
+
TypedDict,
|
|
12
|
+
Union
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
if TYPE_CHECKING:
|
|
17
|
+
from osn_selenium.dev_tools.manager import DevToolsTarget
|
|
18
|
+
from osn_selenium.dev_tools.domains.fetch import request_paused_actions_literal, auth_required_actions_literal
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def request_paused_choose_func(self: "DevToolsTarget", event: Any) -> Sequence["request_paused_actions_literal"]:
|
|
22
|
+
"""
|
|
23
|
+
Default function to choose actions for a 'fetch.RequestPaused' event.
|
|
24
|
+
|
|
25
|
+
This default implementation always chooses to 'continue_request'.
|
|
26
|
+
Users can provide their own function to implement custom logic for
|
|
27
|
+
deciding which actions to take based on the event details.
|
|
28
|
+
|
|
29
|
+
Args:
|
|
30
|
+
self (DevToolsTarget): The DevToolsTarget instance.
|
|
31
|
+
event (Any): The 'RequestPaused' event object.
|
|
32
|
+
|
|
33
|
+
Returns:
|
|
34
|
+
Sequence[request_paused_actions_literal]: A sequence of action names to be executed.
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
return ["continue_request"]
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def on_error_func(self: "DevToolsTarget", event: Any, error: BaseException):
|
|
41
|
+
"""
|
|
42
|
+
Default error handling function for DevTools event listeners.
|
|
43
|
+
|
|
44
|
+
This function simply logs the error using the internal error logging utility.
|
|
45
|
+
Users can provide their own function to implement custom error handling logic.
|
|
46
|
+
|
|
47
|
+
Args:
|
|
48
|
+
self (DevToolsTarget): The DevToolsTarget instance.
|
|
49
|
+
event (Any): The event object that was being processed when the error occurred.
|
|
50
|
+
error (BaseException): The exception that was raised.
|
|
51
|
+
"""
|
|
52
|
+
|
|
53
|
+
log_exception(error)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class HeaderInstance(TypedDict):
|
|
57
|
+
"""
|
|
58
|
+
Type definition for header modification instructions used by the `headers_handler`.
|
|
59
|
+
|
|
60
|
+
This TypedDict is used to specify how a header should be modified when intercepting network requests using DevTools.
|
|
61
|
+
It includes the new value for the header and an instruction on how to apply the change (set, set if exists, remove).
|
|
62
|
+
|
|
63
|
+
Attributes:
|
|
64
|
+
value (Union[str, Any]): The new value to set for the header. Can be a string or any other type that can be converted to a string for the header value.
|
|
65
|
+
instruction (Literal["set", "set_exist", "remove"]): Specifies the type of modification to apply to the header.
|
|
66
|
+
|
|
67
|
+
- "set": Sets the header to the provided `value`, overwriting any existing value or adding it if not present.
|
|
68
|
+
- "set_exist": Sets the header to the provided `value` only if the header already exists in the request.
|
|
69
|
+
- "remove": Removes the header from the request if it exists.
|
|
70
|
+
"""
|
|
71
|
+
|
|
72
|
+
value: Union[str, Any]
|
|
73
|
+
instruction: Union[Literal["set", "set_exist", "remove"], Any]
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
async def headers_handler(
|
|
77
|
+
self: "DevToolsTarget",
|
|
78
|
+
ready_event: trio.Event,
|
|
79
|
+
headers_instances: dict[str, HeaderInstance],
|
|
80
|
+
event: Any,
|
|
81
|
+
kwargs: dict[str, Any]
|
|
82
|
+
):
|
|
83
|
+
"""
|
|
84
|
+
A parameter handler function to modify request headers.
|
|
85
|
+
|
|
86
|
+
This handler processes a dictionary of header modification instructions (`headers_instances`)
|
|
87
|
+
and applies them to the request headers found in the `event` object. The modified headers
|
|
88
|
+
are then added to the `kwargs` dictionary, which will be used for a CDP command
|
|
89
|
+
like `fetch.continueRequest`.
|
|
90
|
+
|
|
91
|
+
Args:
|
|
92
|
+
self (DevToolsTarget): The DevToolsTarget instance.
|
|
93
|
+
ready_event (trio.Event): A Trio event to signal when the handler has completed its work.
|
|
94
|
+
headers_instances (dict[str, HeaderInstance]): A dictionary where keys are header names
|
|
95
|
+
and values are `HeaderInstance` objects defining the modification.
|
|
96
|
+
event (Any): The CDP event object (e.g., `RequestPaused`) containing the original request headers.
|
|
97
|
+
kwargs (dict[str, Any]): The dictionary of keyword arguments to which the modified headers will be added.
|
|
98
|
+
|
|
99
|
+
Raises:
|
|
100
|
+
Exception: If an error occurs during header modification.
|
|
101
|
+
"""
|
|
102
|
+
|
|
103
|
+
try:
|
|
104
|
+
header_entry_class = await self.get_devtools_object("fetch.HeaderEntry")
|
|
105
|
+
headers = {name: value for name, value in event.request.headers.items()}
|
|
106
|
+
|
|
107
|
+
for name, instance in headers_instances.items():
|
|
108
|
+
value = instance["value"]
|
|
109
|
+
instruction = instance["instruction"]
|
|
110
|
+
|
|
111
|
+
if instruction == "set":
|
|
112
|
+
headers[name] = value
|
|
113
|
+
continue
|
|
114
|
+
|
|
115
|
+
if instruction == "set_exist":
|
|
116
|
+
if name in headers:
|
|
117
|
+
headers[name] = value
|
|
118
|
+
|
|
119
|
+
continue
|
|
120
|
+
|
|
121
|
+
if instruction == "remove":
|
|
122
|
+
if name in headers:
|
|
123
|
+
headers.pop(name)
|
|
124
|
+
|
|
125
|
+
continue
|
|
126
|
+
|
|
127
|
+
kwargs["headers"] = [
|
|
128
|
+
header_entry_class(name=name, value=value)
|
|
129
|
+
for name, value in headers.items()
|
|
130
|
+
]
|
|
131
|
+
|
|
132
|
+
ready_event.set()
|
|
133
|
+
except BaseException as error:
|
|
134
|
+
await self.log_error(error=error)
|
|
135
|
+
raise error
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def auth_required_choose_func(self: "DevToolsTarget", target_data: TargetData, event: Any) -> Sequence["auth_required_actions_literal"]:
|
|
139
|
+
"""
|
|
140
|
+
Default function to choose actions for a 'fetch.AuthRequired' event.
|
|
141
|
+
|
|
142
|
+
This default implementation always chooses to 'continue_with_auth'.
|
|
143
|
+
Users can provide their own function to implement custom logic for
|
|
144
|
+
deciding which actions to take based on the event details.
|
|
145
|
+
|
|
146
|
+
Args:
|
|
147
|
+
self (DevToolsTarget): The DevToolsTarget instance.
|
|
148
|
+
target_data (TargetData): Data about the current browser target.
|
|
149
|
+
event (Any): The 'AuthRequired' event object.
|
|
150
|
+
|
|
151
|
+
Returns:
|
|
152
|
+
Sequence[auth_required_actions_literal]: A sequence of action names to be executed.
|
|
153
|
+
"""
|
|
154
|
+
|
|
155
|
+
return ["continue_with_auth"]
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import trio
|
|
2
|
+
from selenium.webdriver.common.bidi.cdp import CdpConnectionClosed
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class WrongHandlerSettingsTypeError(Exception):
|
|
6
|
+
"""
|
|
7
|
+
Custom exception raised when the event handler settings type is incorrect.
|
|
8
|
+
|
|
9
|
+
This exception is raised when the provided handler settings is not a dictionary,
|
|
10
|
+
but expected to be for proper configuration of event handlers.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
def __init__(self, handler_settings_type: type):
|
|
14
|
+
"""
|
|
15
|
+
Initializes WrongHandlerSettingsTypeError with the incorrect settings type.
|
|
16
|
+
|
|
17
|
+
Args:
|
|
18
|
+
handler_settings_type (type): The type of the handler settings that caused the error.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
super().__init__(
|
|
22
|
+
f"Wrong event handler settings type ({handler_settings_type}). It must be a dict!"
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class WrongHandlerSettingsError(Exception):
|
|
27
|
+
"""
|
|
28
|
+
Custom exception raised when event handler settings are incorrect.
|
|
29
|
+
|
|
30
|
+
This exception is raised if the provided handler settings dictionary does not contain
|
|
31
|
+
exactly one of the expected keys, as specified in the `one_of` attribute.
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
def __init__(self, handler_settings: dict, one_of: list[str]):
|
|
35
|
+
"""
|
|
36
|
+
Initializes WrongHandlerSettingsError with the incorrect handler settings and expected keys.
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
handler_settings (dict[str, Any]): The dictionary of handler settings that caused the error.
|
|
40
|
+
one_of (Sequence[str]): A list of expected keys, exactly one of which should be in `handler_settings`.
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
super().__init__(
|
|
44
|
+
f"Wrong event handler settings ({handler_settings})\n\nIt must contain exactly one of {one_of} keys!"
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class CantEnterDevToolsContextError(Exception):
|
|
49
|
+
"""
|
|
50
|
+
Custom exception raised when unable to enter the DevTools context.
|
|
51
|
+
|
|
52
|
+
This exception is raised when the attempt to switch the WebDriver's context to
|
|
53
|
+
the DevTools frame fails, preventing further DevTools interactions.
|
|
54
|
+
"""
|
|
55
|
+
|
|
56
|
+
def __init__(self, reason: str):
|
|
57
|
+
"""
|
|
58
|
+
Initializes CantEnterDevToolsContextError with the reason of failure.
|
|
59
|
+
|
|
60
|
+
Args:
|
|
61
|
+
reason (str): The reason why entering the DevTools context failed.
|
|
62
|
+
"""
|
|
63
|
+
|
|
64
|
+
super().__init__(f"Can't enter devtools context! Reason: {reason}.")
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class BidiConnectionNotEstablishedError(Exception):
|
|
68
|
+
"""
|
|
69
|
+
Custom exception raised when a BiDi connection is required but not established.
|
|
70
|
+
|
|
71
|
+
This indicates that a DevTools operation was attempted before the `DevTools`
|
|
72
|
+
context manager was entered, which establishes the necessary BiDi connection.
|
|
73
|
+
"""
|
|
74
|
+
|
|
75
|
+
def __init__(self):
|
|
76
|
+
"""
|
|
77
|
+
Initializes BidiConnectionNotEstablishedError.
|
|
78
|
+
"""
|
|
79
|
+
|
|
80
|
+
super().__init__("Bidi connection not established. Enter the DevTools context first!")
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
trio_end_exceptions = (trio.Cancelled, trio.EndOfChannel, trio.ClosedResourceError)
|
|
84
|
+
cdp_end_exceptions = (
|
|
85
|
+
trio.Cancelled,
|
|
86
|
+
trio.EndOfChannel,
|
|
87
|
+
trio.ClosedResourceError,
|
|
88
|
+
CdpConnectionClosed
|
|
89
|
+
)
|