osn-selenium 1.0.0__py3-none-any.whl → 1.2.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/_base_models.py +41 -0
- osn_selenium/_cdp_import.py +253 -0
- osn_selenium/_decorators.py +57 -0
- osn_selenium/_trio_threads_helpers.py +157 -0
- osn_selenium/_typehints.py +1 -1
- osn_selenium/abstract/executors/cdp.py +63 -0
- osn_selenium/abstract/webdriver/blink/base.py +14 -0
- osn_selenium/abstract/webdriver/blink/lifecycle.py +8 -8
- osn_selenium/abstract/webdriver/core/base.py +0 -14
- osn_selenium/abstract/webdriver/core/capture.py +4 -3
- osn_selenium/abstract/webdriver/core/lifecycle.py +8 -8
- osn_selenium/abstract/webdriver/core/script.py +5 -4
- osn_selenium/abstract/webdriver/core/window.py +11 -11
- osn_selenium/browsers_handler/models.py +1 -1
- osn_selenium/dev_tools/_decorators.py +19 -51
- osn_selenium/dev_tools/_functions.py +2 -4
- osn_selenium/dev_tools/_typehints.py +5 -2
- osn_selenium/dev_tools/_wrappers.py +0 -3
- osn_selenium/dev_tools/domains/__init__.py +2 -2
- osn_selenium/dev_tools/domains/abstract.py +1 -1
- osn_selenium/dev_tools/domains/fetch.py +6 -8
- osn_selenium/dev_tools/domains_default/fetch.py +2 -2
- osn_selenium/dev_tools/filters.py +1 -1
- osn_selenium/dev_tools/logger/main.py +9 -21
- osn_selenium/dev_tools/logger/models.py +1 -1
- osn_selenium/dev_tools/logger/target.py +49 -29
- osn_selenium/dev_tools/manager/base.py +10 -42
- osn_selenium/dev_tools/manager/lifecycle.py +84 -75
- osn_selenium/dev_tools/manager/logging.py +1 -1
- osn_selenium/dev_tools/manager/targets.py +13 -5
- osn_selenium/dev_tools/models.py +1 -1
- osn_selenium/dev_tools/settings.py +9 -5
- osn_selenium/dev_tools/target/base.py +30 -34
- osn_selenium/dev_tools/target/discovery.py +1 -1
- osn_selenium/dev_tools/target/events.py +2 -2
- osn_selenium/dev_tools/target/fingerprint.py +1 -1
- osn_selenium/dev_tools/target/lifecycle.py +103 -38
- osn_selenium/dev_tools/target/logging.py +11 -3
- osn_selenium/exceptions/__init__.py +0 -1
- osn_selenium/exceptions/base.py +28 -1
- osn_selenium/exceptions/bidi_bridge.py +59 -0
- osn_selenium/exceptions/configuration.py +1 -8
- osn_selenium/exceptions/dependencies.py +60 -0
- osn_selenium/exceptions/devtools.py +9 -39
- osn_selenium/exceptions/experimental.py +26 -0
- osn_selenium/exceptions/flags.py +0 -2
- osn_selenium/exceptions/instance.py +1 -9
- osn_selenium/exceptions/javascript.py +0 -2
- osn_selenium/exceptions/logic.py +0 -2
- osn_selenium/exceptions/path.py +1 -9
- osn_selenium/exceptions/platform.py +0 -2
- osn_selenium/exceptions/protocol.py +0 -3
- osn_selenium/exceptions/webdriver.py +1 -7
- osn_selenium/exceptions/window.py +1 -8
- osn_selenium/executors/sync/cdp.py +95 -0
- osn_selenium/executors/trio_bidi/cdp.py +101 -0
- osn_selenium/executors/trio_bidi/javascript.py +101 -0
- osn_selenium/executors/trio_threads/cdp.py +99 -0
- osn_selenium/executors/trio_threads/javascript.py +1 -1
- osn_selenium/executors/unified/javascript.py +0 -4
- osn_selenium/flags/base.py +7 -13
- osn_selenium/flags/blink.py +2 -8
- osn_selenium/flags/chrome.py +6 -6
- osn_selenium/flags/edge.py +6 -6
- osn_selenium/flags/models/base.py +4 -4
- osn_selenium/flags/models/blink.py +1 -1
- osn_selenium/flags/models/values.py +1 -1
- osn_selenium/instances/convert.py +44 -3
- osn_selenium/instances/protocols.py +47 -1
- osn_selenium/instances/sync/action_chains/__init__.py +6 -0
- osn_selenium/instances/sync/browsing_context.py +2 -2
- osn_selenium/instances/sync/script.py +7 -2
- osn_selenium/instances/sync/shadow_root.py +30 -8
- osn_selenium/instances/sync/web_element.py +1 -1
- osn_selenium/instances/trio_bidi/__init__.py +1 -0
- osn_selenium/instances/trio_bidi/shadow_root.py +180 -0
- osn_selenium/instances/trio_bidi/switch_to.py +143 -0
- osn_selenium/instances/trio_bidi/web_driver_wait.py +124 -0
- osn_selenium/instances/trio_bidi/web_element.py +239 -0
- osn_selenium/instances/trio_threads/action_chains/__init__.py +6 -0
- osn_selenium/instances/trio_threads/action_chains/base.py +1 -1
- osn_selenium/instances/trio_threads/alert.py +1 -1
- osn_selenium/instances/trio_threads/browser.py +1 -1
- osn_selenium/instances/trio_threads/browsing_context.py +3 -3
- osn_selenium/instances/trio_threads/dialog.py +1 -1
- osn_selenium/instances/trio_threads/fedcm.py +1 -1
- osn_selenium/instances/trio_threads/mobile.py +1 -1
- osn_selenium/instances/trio_threads/network.py +1 -1
- osn_selenium/instances/trio_threads/permissions.py +1 -1
- osn_selenium/instances/trio_threads/script.py +8 -3
- osn_selenium/instances/trio_threads/shadow_root.py +46 -15
- osn_selenium/instances/trio_threads/storage.py +1 -1
- osn_selenium/instances/trio_threads/switch_to.py +1 -1
- osn_selenium/instances/trio_threads/web_driver_wait.py +1 -1
- osn_selenium/instances/trio_threads/web_element.py +1 -1
- osn_selenium/instances/trio_threads/web_extension.py +1 -1
- osn_selenium/instances/unified/browsing_context.py +2 -2
- osn_selenium/instances/unified/script.py +2 -2
- osn_selenium/instances/unified/web_element.py +3 -5
- osn_selenium/javascript/fingerprint/__init__.py +3 -2
- osn_selenium/javascript/fingerprint/registry/models.py +1 -1
- osn_selenium/javascript/fingerprint/spoof/core_rules.py +1 -1
- osn_selenium/javascript/fingerprint/spoof/noise.py +1 -1
- osn_selenium/javascript/models.py +1 -1
- osn_selenium/models.py +2 -47
- osn_selenium/trio_bidi/__init__.py +1 -0
- osn_selenium/trio_bidi/_context_vars.py +12 -0
- osn_selenium/trio_bidi/_error_mappings.py +123 -0
- osn_selenium/trio_bidi/_error_redirects.py +194 -0
- osn_selenium/trio_bidi/_file_functions.py +28 -0
- osn_selenium/trio_bidi/_internal_mappings.py +10 -0
- osn_selenium/trio_bidi/_models.py +199 -0
- osn_selenium/trio_bidi/_typehints.py +20 -0
- osn_selenium/trio_bidi/connection_pool.py +587 -0
- osn_selenium/trio_bidi/mapping/__init__.py +1 -0
- osn_selenium/trio_bidi/mapping/_constants.py +14 -0
- osn_selenium/trio_bidi/mapping/_js_snippets.py +285 -0
- osn_selenium/trio_bidi/mapping/_utils.py +4 -0
- osn_selenium/trio_bidi/mapping/request_functions/__init__.py +87 -0
- osn_selenium/trio_bidi/mapping/request_functions/_alert.py +102 -0
- osn_selenium/trio_bidi/mapping/request_functions/_args_helpers.py +225 -0
- osn_selenium/trio_bidi/mapping/request_functions/_capture.py +71 -0
- osn_selenium/trio_bidi/mapping/request_functions/_cdp.py +40 -0
- osn_selenium/trio_bidi/mapping/request_functions/_element.py +55 -0
- osn_selenium/trio_bidi/mapping/request_functions/_file.py +32 -0
- osn_selenium/trio_bidi/mapping/request_functions/_navigation.py +147 -0
- osn_selenium/trio_bidi/mapping/request_functions/_script.py +85 -0
- osn_selenium/trio_bidi/mapping/request_functions/_shadow_root.py +65 -0
- osn_selenium/trio_bidi/mapping/request_functions/_switch_to.py +59 -0
- osn_selenium/trio_bidi/mapping/request_functions/_web_element.py +448 -0
- osn_selenium/trio_bidi/mapping/request_functions/_window.py +125 -0
- osn_selenium/trio_bidi/mapping/response_functions/__init__.py +86 -0
- osn_selenium/trio_bidi/mapping/response_functions/_alert.py +81 -0
- osn_selenium/trio_bidi/mapping/response_functions/_args_helpers.py +183 -0
- osn_selenium/trio_bidi/mapping/response_functions/_args_validators.py +153 -0
- osn_selenium/trio_bidi/mapping/response_functions/_capture.py +71 -0
- osn_selenium/trio_bidi/mapping/response_functions/_cdp.py +26 -0
- osn_selenium/trio_bidi/mapping/response_functions/_element.py +58 -0
- osn_selenium/trio_bidi/mapping/response_functions/_file.py +30 -0
- osn_selenium/trio_bidi/mapping/response_functions/_navigation.py +120 -0
- osn_selenium/trio_bidi/mapping/response_functions/_script.py +57 -0
- osn_selenium/trio_bidi/mapping/response_functions/_shadow_root.py +58 -0
- osn_selenium/trio_bidi/mapping/response_functions/_switch_to.py +57 -0
- osn_selenium/trio_bidi/mapping/response_functions/_web_element.py +368 -0
- osn_selenium/trio_bidi/mapping/response_functions/_window.py +119 -0
- osn_selenium/trio_bidi/mixin.py +186 -0
- osn_selenium/trio_bidi/remote_connection.py +164 -0
- osn_selenium/{base_mixin.py → trio_threads_mixin.py} +31 -40
- osn_selenium/webdrivers/_args_helpers.py +120 -7
- osn_selenium/webdrivers/_bridges.py +2 -2
- osn_selenium/webdrivers/_executable_tables/models.py +1 -1
- osn_selenium/webdrivers/_typehints.py +9 -3
- osn_selenium/webdrivers/protocols.py +81 -1
- osn_selenium/webdrivers/sync/blink/__init__.py +11 -1
- osn_selenium/webdrivers/sync/blink/base.py +23 -1
- osn_selenium/webdrivers/sync/blink/lifecycle.py +26 -8
- osn_selenium/webdrivers/sync/chrome/__init__.py +36 -1
- osn_selenium/webdrivers/sync/chrome/base.py +13 -1
- osn_selenium/webdrivers/sync/chrome/lifecycle.py +23 -5
- osn_selenium/webdrivers/sync/chrome/settings.py +6 -1
- osn_selenium/webdrivers/sync/core/__init__.py +10 -1
- osn_selenium/webdrivers/sync/core/base.py +18 -18
- osn_selenium/webdrivers/sync/core/capture.py +3 -2
- osn_selenium/webdrivers/sync/core/file.py +3 -2
- osn_selenium/webdrivers/sync/core/lifecycle.py +44 -10
- osn_selenium/webdrivers/sync/core/script.py +3 -2
- osn_selenium/webdrivers/sync/core/window.py +3 -3
- osn_selenium/webdrivers/sync/edge/__init__.py +36 -1
- osn_selenium/webdrivers/sync/edge/base.py +13 -1
- osn_selenium/webdrivers/sync/edge/lifecycle.py +23 -5
- osn_selenium/webdrivers/sync/edge/settings.py +6 -1
- osn_selenium/webdrivers/sync/yandex/__init__.py +36 -1
- osn_selenium/webdrivers/sync/yandex/base.py +13 -1
- osn_selenium/webdrivers/sync/yandex/lifecycle.py +23 -5
- osn_selenium/webdrivers/sync/yandex/settings.py +6 -1
- osn_selenium/webdrivers/trio_bidi/__init__.py +1 -0
- osn_selenium/webdrivers/trio_bidi/blink/__init__.py +132 -0
- osn_selenium/webdrivers/trio_bidi/blink/base.py +167 -0
- osn_selenium/webdrivers/trio_bidi/blink/lifecycle.py +89 -0
- osn_selenium/webdrivers/trio_bidi/blink/settings.py +63 -0
- osn_selenium/webdrivers/trio_bidi/chrome/__init__.py +114 -0
- osn_selenium/webdrivers/trio_bidi/chrome/base.py +127 -0
- osn_selenium/webdrivers/trio_bidi/chrome/lifecycle.py +85 -0
- osn_selenium/webdrivers/trio_bidi/chrome/settings.py +63 -0
- osn_selenium/webdrivers/trio_bidi/core/__init__.py +95 -0
- osn_selenium/webdrivers/trio_bidi/core/actions.py +70 -0
- osn_selenium/webdrivers/trio_bidi/core/base.py +200 -0
- osn_selenium/webdrivers/trio_bidi/core/capture.py +39 -0
- osn_selenium/webdrivers/trio_bidi/core/devtools.py +49 -0
- osn_selenium/webdrivers/trio_bidi/core/element.py +64 -0
- osn_selenium/webdrivers/trio_bidi/core/lifecycle.py +135 -0
- osn_selenium/webdrivers/trio_bidi/core/navigation.py +37 -0
- osn_selenium/webdrivers/trio_bidi/core/script.py +56 -0
- osn_selenium/webdrivers/trio_bidi/core/settings.py +36 -0
- osn_selenium/webdrivers/trio_bidi/core/window.py +134 -0
- osn_selenium/webdrivers/trio_bidi/edge/__init__.py +114 -0
- osn_selenium/webdrivers/trio_bidi/edge/base.py +123 -0
- osn_selenium/webdrivers/trio_bidi/edge/lifecycle.py +85 -0
- osn_selenium/webdrivers/trio_bidi/edge/settings.py +63 -0
- osn_selenium/webdrivers/trio_bidi/yandex/__init__.py +114 -0
- osn_selenium/webdrivers/trio_bidi/yandex/base.py +120 -0
- osn_selenium/webdrivers/trio_bidi/yandex/lifecycle.py +85 -0
- osn_selenium/webdrivers/trio_bidi/yandex/settings.py +63 -0
- osn_selenium/webdrivers/trio_threads/blink/__init__.py +18 -2
- osn_selenium/webdrivers/trio_threads/blink/base.py +25 -1
- osn_selenium/webdrivers/trio_threads/blink/casting.py +1 -1
- osn_selenium/webdrivers/trio_threads/blink/features.py +1 -1
- osn_selenium/webdrivers/trio_threads/blink/lifecycle.py +26 -8
- osn_selenium/webdrivers/trio_threads/blink/logging.py +1 -1
- osn_selenium/webdrivers/trio_threads/blink/network.py +1 -1
- osn_selenium/webdrivers/trio_threads/chrome/__init__.py +34 -1
- osn_selenium/webdrivers/trio_threads/chrome/base.py +14 -2
- osn_selenium/webdrivers/trio_threads/chrome/lifecycle.py +23 -5
- osn_selenium/webdrivers/trio_threads/chrome/settings.py +1 -1
- osn_selenium/webdrivers/trio_threads/core/__init__.py +10 -14
- osn_selenium/webdrivers/trio_threads/core/actions.py +1 -1
- osn_selenium/webdrivers/trio_threads/core/auth.py +1 -1
- osn_selenium/webdrivers/trio_threads/core/base.py +18 -22
- osn_selenium/webdrivers/trio_threads/core/capture.py +4 -3
- osn_selenium/webdrivers/trio_threads/core/comonents.py +1 -1
- osn_selenium/webdrivers/trio_threads/core/devtools.py +1 -1
- osn_selenium/webdrivers/trio_threads/core/element.py +1 -1
- osn_selenium/webdrivers/trio_threads/core/file.py +5 -4
- osn_selenium/webdrivers/trio_threads/core/lifecycle.py +45 -11
- osn_selenium/webdrivers/trio_threads/core/navigation.py +1 -1
- osn_selenium/webdrivers/trio_threads/core/script.py +4 -3
- osn_selenium/webdrivers/trio_threads/core/settings.py +1 -1
- osn_selenium/webdrivers/trio_threads/core/storage.py +1 -1
- osn_selenium/webdrivers/trio_threads/core/timeouts.py +1 -1
- osn_selenium/webdrivers/trio_threads/core/window.py +6 -6
- osn_selenium/webdrivers/trio_threads/edge/__init__.py +34 -1
- osn_selenium/webdrivers/trio_threads/edge/base.py +14 -2
- osn_selenium/webdrivers/trio_threads/edge/lifecycle.py +23 -5
- osn_selenium/webdrivers/trio_threads/edge/settings.py +1 -1
- osn_selenium/webdrivers/trio_threads/yandex/__init__.py +34 -1
- osn_selenium/webdrivers/trio_threads/yandex/base.py +14 -2
- osn_selenium/webdrivers/trio_threads/yandex/lifecycle.py +23 -5
- osn_selenium/webdrivers/trio_threads/yandex/settings.py +1 -1
- osn_selenium/webdrivers/unified/blink/base.py +9 -1
- osn_selenium/webdrivers/unified/blink/lifecycle.py +4 -2
- osn_selenium/webdrivers/unified/chrome/base.py +9 -1
- osn_selenium/webdrivers/unified/core/auth.py +4 -2
- osn_selenium/webdrivers/unified/core/base.py +19 -6
- osn_selenium/webdrivers/unified/core/capture.py +3 -2
- osn_selenium/webdrivers/unified/core/components.py +12 -7
- osn_selenium/webdrivers/unified/core/devtools.py +2 -1
- osn_selenium/webdrivers/unified/core/file.py +3 -2
- osn_selenium/webdrivers/unified/core/lifecycle.py +5 -3
- osn_selenium/webdrivers/unified/core/script.py +5 -3
- osn_selenium/webdrivers/unified/core/storage.py +2 -1
- osn_selenium/webdrivers/unified/core/window.py +9 -8
- osn_selenium/webdrivers/unified/edge/base.py +9 -1
- osn_selenium/webdrivers/unified/yandex/base.py +9 -1
- {osn_selenium-1.0.0.dist-info → osn_selenium-1.2.0.dist-info}/METADATA +24 -10
- osn_selenium-1.2.0.dist-info/RECORD +480 -0
- {osn_selenium-1.0.0.dist-info → osn_selenium-1.2.0.dist-info}/WHEEL +1 -1
- osn_selenium/abstract/executors/cdp/__init__.py +0 -435
- osn_selenium/abstract/executors/cdp/accessibility.py +0 -62
- osn_selenium/abstract/executors/cdp/animation.py +0 -47
- osn_selenium/abstract/executors/cdp/audits.py +0 -39
- osn_selenium/abstract/executors/cdp/autofill.py +0 -34
- osn_selenium/abstract/executors/cdp/background_service.py +0 -22
- osn_selenium/abstract/executors/cdp/bluetooth_emulation.py +0 -95
- osn_selenium/abstract/executors/cdp/browser.py +0 -122
- osn_selenium/abstract/executors/cdp/cache_storage.py +0 -49
- osn_selenium/abstract/executors/cdp/cast.py +0 -31
- osn_selenium/abstract/executors/cdp/console.py +0 -18
- osn_selenium/abstract/executors/cdp/css.py +0 -197
- osn_selenium/abstract/executors/cdp/debugger.py +0 -198
- osn_selenium/abstract/executors/cdp/device_access.py +0 -22
- osn_selenium/abstract/executors/cdp/device_orientation.py +0 -14
- osn_selenium/abstract/executors/cdp/dom.py +0 -305
- osn_selenium/abstract/executors/cdp/dom_debugger.py +0 -57
- osn_selenium/abstract/executors/cdp/dom_snapshot.py +0 -42
- osn_selenium/abstract/executors/cdp/dom_storage.py +0 -31
- osn_selenium/abstract/executors/cdp/emulation.py +0 -259
- osn_selenium/abstract/executors/cdp/event_breakpoints.py +0 -18
- osn_selenium/abstract/executors/cdp/extensions.py +0 -31
- osn_selenium/abstract/executors/cdp/fed_cm.py +0 -35
- osn_selenium/abstract/executors/cdp/fetch.py +0 -76
- osn_selenium/abstract/executors/cdp/file_system.py +0 -11
- osn_selenium/abstract/executors/cdp/headless_experimental.py +0 -30
- osn_selenium/abstract/executors/cdp/heap_profiler.py +0 -73
- osn_selenium/abstract/executors/cdp/indexed_db.py +0 -99
- osn_selenium/abstract/executors/cdp/input.py +0 -158
- osn_selenium/abstract/executors/cdp/inspector.py +0 -14
- osn_selenium/abstract/executors/cdp/io.py +0 -24
- osn_selenium/abstract/executors/cdp/layer_tree.py +0 -61
- osn_selenium/abstract/executors/cdp/log.py +0 -27
- osn_selenium/abstract/executors/cdp/media.py +0 -14
- osn_selenium/abstract/executors/cdp/memory.py +0 -61
- osn_selenium/abstract/executors/cdp/network.py +0 -252
- osn_selenium/abstract/executors/cdp/overlay.py +0 -166
- osn_selenium/abstract/executors/cdp/page.py +0 -347
- osn_selenium/abstract/executors/cdp/performance.py +0 -28
- osn_selenium/abstract/executors/cdp/performance_timeline.py +0 -11
- osn_selenium/abstract/executors/cdp/preload.py +0 -14
- osn_selenium/abstract/executors/cdp/profiler.py +0 -54
- osn_selenium/abstract/executors/cdp/pwa.py +0 -46
- osn_selenium/abstract/executors/cdp/runtime.py +0 -176
- osn_selenium/abstract/executors/cdp/schema.py +0 -11
- osn_selenium/abstract/executors/cdp/security.py +0 -26
- osn_selenium/abstract/executors/cdp/service_worker.py +0 -54
- osn_selenium/abstract/executors/cdp/storage.py +0 -175
- osn_selenium/abstract/executors/cdp/system_info.py +0 -24
- osn_selenium/abstract/executors/cdp/target.py +0 -125
- osn_selenium/abstract/executors/cdp/tethering.py +0 -14
- osn_selenium/abstract/executors/cdp/tracing.py +0 -48
- osn_selenium/abstract/executors/cdp/web_audio.py +0 -19
- osn_selenium/abstract/executors/cdp/web_authn.py +0 -76
- osn_selenium/executors/sync/cdp/__init__.py +0 -550
- osn_selenium/executors/sync/cdp/accessibility.py +0 -74
- osn_selenium/executors/sync/cdp/animation.py +0 -50
- osn_selenium/executors/sync/cdp/audits.py +0 -48
- osn_selenium/executors/sync/cdp/autofill.py +0 -39
- osn_selenium/executors/sync/cdp/background_service.py +0 -30
- osn_selenium/executors/sync/cdp/bluetooth_emulation.py +0 -101
- osn_selenium/executors/sync/cdp/browser.py +0 -131
- osn_selenium/executors/sync/cdp/cache_storage.py +0 -66
- osn_selenium/executors/sync/cdp/cast.py +0 -38
- osn_selenium/executors/sync/cdp/console.py +0 -24
- osn_selenium/executors/sync/cdp/css.py +0 -187
- osn_selenium/executors/sync/cdp/debugger.py +0 -206
- osn_selenium/executors/sync/cdp/device_access.py +0 -27
- osn_selenium/executors/sync/cdp/device_orientation.py +0 -24
- osn_selenium/executors/sync/cdp/dom.py +0 -310
- osn_selenium/executors/sync/cdp/dom_debugger.py +0 -56
- osn_selenium/executors/sync/cdp/dom_snapshot.py +0 -58
- osn_selenium/executors/sync/cdp/dom_storage.py +0 -38
- osn_selenium/executors/sync/cdp/emulation.py +0 -270
- osn_selenium/executors/sync/cdp/event_breakpoints.py +0 -27
- osn_selenium/executors/sync/cdp/extensions.py +0 -39
- osn_selenium/executors/sync/cdp/fed_cm.py +0 -45
- osn_selenium/executors/sync/cdp/fetch.py +0 -96
- osn_selenium/executors/sync/cdp/file_system.py +0 -18
- osn_selenium/executors/sync/cdp/headless_experimental.py +0 -44
- osn_selenium/executors/sync/cdp/heap_profiler.py +0 -89
- osn_selenium/executors/sync/cdp/indexed_db.py +0 -142
- osn_selenium/executors/sync/cdp/input.py +0 -233
- osn_selenium/executors/sync/cdp/inspector.py +0 -21
- osn_selenium/executors/sync/cdp/io.py +0 -33
- osn_selenium/executors/sync/cdp/layer_tree.py +0 -71
- osn_selenium/executors/sync/cdp/log.py +0 -35
- osn_selenium/executors/sync/cdp/media.py +0 -21
- osn_selenium/executors/sync/cdp/memory.py +0 -62
- osn_selenium/executors/sync/cdp/network.py +0 -287
- osn_selenium/executors/sync/cdp/overlay.py +0 -174
- osn_selenium/executors/sync/cdp/page.py +0 -365
- osn_selenium/executors/sync/cdp/performance.py +0 -33
- osn_selenium/executors/sync/cdp/performance_timeline.py +0 -26
- osn_selenium/executors/sync/cdp/preload.py +0 -21
- osn_selenium/executors/sync/cdp/profiler.py +0 -58
- osn_selenium/executors/sync/cdp/pwa.py +0 -55
- osn_selenium/executors/sync/cdp/runtime.py +0 -221
- osn_selenium/executors/sync/cdp/schema.py +0 -23
- osn_selenium/executors/sync/cdp/security.py +0 -30
- osn_selenium/executors/sync/cdp/service_worker.py +0 -56
- osn_selenium/executors/sync/cdp/storage.py +0 -151
- osn_selenium/executors/sync/cdp/system_info.py +0 -30
- osn_selenium/executors/sync/cdp/target.py +0 -147
- osn_selenium/executors/sync/cdp/tethering.py +0 -21
- osn_selenium/executors/sync/cdp/tracing.py +0 -62
- osn_selenium/executors/sync/cdp/web_audio.py +0 -24
- osn_selenium/executors/sync/cdp/web_authn.py +0 -82
- osn_selenium/executors/trio_threads/cdp/__init__.py +0 -771
- osn_selenium/executors/trio_threads/cdp/accessibility.py +0 -87
- osn_selenium/executors/trio_threads/cdp/animation.py +0 -63
- osn_selenium/executors/trio_threads/cdp/audits.py +0 -57
- osn_selenium/executors/trio_threads/cdp/autofill.py +0 -52
- osn_selenium/executors/trio_threads/cdp/background_service.py +0 -40
- osn_selenium/executors/trio_threads/cdp/bluetooth_emulation.py +0 -111
- osn_selenium/executors/trio_threads/cdp/browser.py +0 -140
- osn_selenium/executors/trio_threads/cdp/cache_storage.py +0 -79
- osn_selenium/executors/trio_threads/cdp/cast.py +0 -47
- osn_selenium/executors/trio_threads/cdp/console.py +0 -33
- osn_selenium/executors/trio_threads/cdp/css.py +0 -196
- osn_selenium/executors/trio_threads/cdp/debugger.py +0 -219
- osn_selenium/executors/trio_threads/cdp/device_access.py +0 -40
- osn_selenium/executors/trio_threads/cdp/device_orientation.py +0 -34
- osn_selenium/executors/trio_threads/cdp/dom.py +0 -319
- osn_selenium/executors/trio_threads/cdp/dom_debugger.py +0 -69
- osn_selenium/executors/trio_threads/cdp/dom_snapshot.py +0 -71
- osn_selenium/executors/trio_threads/cdp/dom_storage.py +0 -51
- osn_selenium/executors/trio_threads/cdp/emulation.py +0 -283
- osn_selenium/executors/trio_threads/cdp/event_breakpoints.py +0 -37
- osn_selenium/executors/trio_threads/cdp/extensions.py +0 -52
- osn_selenium/executors/trio_threads/cdp/fed_cm.py +0 -54
- osn_selenium/executors/trio_threads/cdp/fetch.py +0 -105
- osn_selenium/executors/trio_threads/cdp/file_system.py +0 -31
- osn_selenium/executors/trio_threads/cdp/headless_experimental.py +0 -54
- osn_selenium/executors/trio_threads/cdp/heap_profiler.py +0 -102
- osn_selenium/executors/trio_threads/cdp/indexed_db.py +0 -155
- osn_selenium/executors/trio_threads/cdp/input.py +0 -242
- osn_selenium/executors/trio_threads/cdp/inspector.py +0 -34
- osn_selenium/executors/trio_threads/cdp/io.py +0 -42
- osn_selenium/executors/trio_threads/cdp/layer_tree.py +0 -84
- osn_selenium/executors/trio_threads/cdp/log.py +0 -44
- osn_selenium/executors/trio_threads/cdp/media.py +0 -30
- osn_selenium/executors/trio_threads/cdp/memory.py +0 -71
- osn_selenium/executors/trio_threads/cdp/network.py +0 -296
- osn_selenium/executors/trio_threads/cdp/overlay.py +0 -183
- osn_selenium/executors/trio_threads/cdp/page.py +0 -374
- osn_selenium/executors/trio_threads/cdp/performance.py +0 -46
- osn_selenium/executors/trio_threads/cdp/performance_timeline.py +0 -36
- osn_selenium/executors/trio_threads/cdp/preload.py +0 -30
- osn_selenium/executors/trio_threads/cdp/profiler.py +0 -71
- osn_selenium/executors/trio_threads/cdp/pwa.py +0 -64
- osn_selenium/executors/trio_threads/cdp/runtime.py +0 -230
- osn_selenium/executors/trio_threads/cdp/schema.py +0 -32
- osn_selenium/executors/trio_threads/cdp/security.py +0 -43
- osn_selenium/executors/trio_threads/cdp/service_worker.py +0 -69
- osn_selenium/executors/trio_threads/cdp/storage.py +0 -162
- osn_selenium/executors/trio_threads/cdp/system_info.py +0 -43
- osn_selenium/executors/trio_threads/cdp/target.py +0 -156
- osn_selenium/executors/trio_threads/cdp/tethering.py +0 -34
- osn_selenium/executors/trio_threads/cdp/tracing.py +0 -71
- osn_selenium/executors/trio_threads/cdp/web_audio.py +0 -37
- osn_selenium/executors/trio_threads/cdp/web_authn.py +0 -95
- osn_selenium/executors/unified/cdp/accessibility.py +0 -81
- osn_selenium/executors/unified/cdp/animation.py +0 -50
- osn_selenium/executors/unified/cdp/audits.py +0 -45
- osn_selenium/executors/unified/cdp/autofill.py +0 -41
- osn_selenium/executors/unified/cdp/background_service.py +0 -24
- osn_selenium/executors/unified/cdp/bluetooth_emulation.py +0 -132
- osn_selenium/executors/unified/cdp/browser.py +0 -143
- osn_selenium/executors/unified/cdp/cache_storage.py +0 -69
- osn_selenium/executors/unified/cdp/cast.py +0 -32
- osn_selenium/executors/unified/cdp/console.py +0 -18
- osn_selenium/executors/unified/cdp/css.py +0 -237
- osn_selenium/executors/unified/cdp/debugger.py +0 -243
- osn_selenium/executors/unified/cdp/device_access.py +0 -21
- osn_selenium/executors/unified/cdp/device_orientation.py +0 -18
- osn_selenium/executors/unified/cdp/dom.py +0 -380
- osn_selenium/executors/unified/cdp/dom_debugger.py +0 -65
- osn_selenium/executors/unified/cdp/dom_snapshot.py +0 -58
- osn_selenium/executors/unified/cdp/dom_storage.py +0 -38
- osn_selenium/executors/unified/cdp/emulation.py +0 -312
- osn_selenium/executors/unified/cdp/event_breakpoints.py +0 -24
- osn_selenium/executors/unified/cdp/extensions.py +0 -45
- osn_selenium/executors/unified/cdp/fed_cm.py +0 -51
- osn_selenium/executors/unified/cdp/fetch.py +0 -111
- osn_selenium/executors/unified/cdp/file_system.py +0 -15
- osn_selenium/executors/unified/cdp/headless_experimental.py +0 -38
- osn_selenium/executors/unified/cdp/heap_profiler.py +0 -101
- osn_selenium/executors/unified/cdp/indexed_db.py +0 -157
- osn_selenium/executors/unified/cdp/input.py +0 -254
- osn_selenium/executors/unified/cdp/inspector.py +0 -15
- osn_selenium/executors/unified/cdp/io.py +0 -29
- osn_selenium/executors/unified/cdp/layer_tree.py +0 -71
- osn_selenium/executors/unified/cdp/log.py +0 -29
- osn_selenium/executors/unified/cdp/media.py +0 -15
- osn_selenium/executors/unified/cdp/memory.py +0 -59
- osn_selenium/executors/unified/cdp/network.py +0 -323
- osn_selenium/executors/unified/cdp/overlay.py +0 -209
- osn_selenium/executors/unified/cdp/page.py +0 -410
- osn_selenium/executors/unified/cdp/performance.py +0 -27
- osn_selenium/executors/unified/cdp/performance_timeline.py +0 -17
- osn_selenium/executors/unified/cdp/preload.py +0 -15
- osn_selenium/executors/unified/cdp/profiler.py +0 -55
- osn_selenium/executors/unified/cdp/pwa.py +0 -55
- osn_selenium/executors/unified/cdp/runtime.py +0 -245
- osn_selenium/executors/unified/cdp/schema.py +0 -17
- osn_selenium/executors/unified/cdp/security.py +0 -27
- osn_selenium/executors/unified/cdp/service_worker.py +0 -62
- osn_selenium/executors/unified/cdp/storage.py +0 -178
- osn_selenium/executors/unified/cdp/system_info.py +0 -24
- osn_selenium/executors/unified/cdp/target.py +0 -165
- osn_selenium/executors/unified/cdp/tethering.py +0 -15
- osn_selenium/executors/unified/cdp/tracing.py +0 -62
- osn_selenium/executors/unified/cdp/web_audio.py +0 -18
- osn_selenium/executors/unified/cdp/web_authn.py +0 -103
- osn_selenium-1.0.0.dist-info/RECORD +0 -608
- /osn_selenium/{dev_tools/_exception_helpers.py → _exception_helpers.py} +0 -0
- /osn_selenium/executors/{unified/cdp → trio_bidi}/__init__.py +0 -0
- {osn_selenium-1.0.0.dist-info → osn_selenium-1.2.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,587 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import json
|
|
3
|
+
import math
|
|
4
|
+
import trio
|
|
5
|
+
import traceback
|
|
6
|
+
import itertools
|
|
7
|
+
from types import TracebackType
|
|
8
|
+
from contextlib import AsyncExitStack
|
|
9
|
+
from osn_selenium._decorators import log_on_error
|
|
10
|
+
from osn_selenium.trio_bidi._file_functions import unzip_file
|
|
11
|
+
from typing import (
|
|
12
|
+
Any,
|
|
13
|
+
Dict,
|
|
14
|
+
Optional,
|
|
15
|
+
Tuple,
|
|
16
|
+
Type,
|
|
17
|
+
Union
|
|
18
|
+
)
|
|
19
|
+
from trio_websocket import (
|
|
20
|
+
WebSocketConnection,
|
|
21
|
+
open_websocket_url
|
|
22
|
+
)
|
|
23
|
+
from osn_selenium.trio_bidi.mapping.request_functions import map_request
|
|
24
|
+
from osn_selenium.trio_bidi.mapping.response_functions import map_response
|
|
25
|
+
from osn_selenium.exceptions.bidi_bridge import (
|
|
26
|
+
BiDiBridgeStoppedError
|
|
27
|
+
)
|
|
28
|
+
from osn_selenium.trio_bidi._error_redirects import (
|
|
29
|
+
redirect_error_response
|
|
30
|
+
)
|
|
31
|
+
from osn_selenium.trio_bidi._typehints import (
|
|
32
|
+
CURRENT_BROWSING_CONTEXT_TYPEHINT
|
|
33
|
+
)
|
|
34
|
+
from osn_selenium.exceptions.devtools import (
|
|
35
|
+
TrioEndExceptions,
|
|
36
|
+
WebSocketEndExceptions
|
|
37
|
+
)
|
|
38
|
+
from osn_selenium.trio_bidi._models import (
|
|
39
|
+
BiDiTask,
|
|
40
|
+
BiDiTaskContainer,
|
|
41
|
+
W3CTask,
|
|
42
|
+
W3CTaskContainer
|
|
43
|
+
)
|
|
44
|
+
from osn_selenium.trio_bidi._internal_mappings import (
|
|
45
|
+
GET_INTERNAL_ALERT_TEXT,
|
|
46
|
+
UPLOAD_INTERNAL_FILE
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
__all__ = ["BiDiConnectionPool"]
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class _WebsocketResponseHandler:
|
|
54
|
+
"""
|
|
55
|
+
Internal handler for reading and dispatching WebSocket messages.
|
|
56
|
+
"""
|
|
57
|
+
|
|
58
|
+
def __init__(self, connection_pool: "BiDiConnectionPool"):
|
|
59
|
+
"""
|
|
60
|
+
Initializes the response handler.
|
|
61
|
+
|
|
62
|
+
Args:
|
|
63
|
+
connection_pool (BiDiConnectionPool): The parent connection pool.
|
|
64
|
+
"""
|
|
65
|
+
|
|
66
|
+
self._connection_pool = connection_pool
|
|
67
|
+
|
|
68
|
+
async def _handle_normal_response(self, response_data: Dict[str, Any]) -> bool:
|
|
69
|
+
"""
|
|
70
|
+
Handles responses for specific BiDi tasks.
|
|
71
|
+
|
|
72
|
+
Args:
|
|
73
|
+
response_data (Dict[str, Any]): The response data from BiDi.
|
|
74
|
+
|
|
75
|
+
Returns:
|
|
76
|
+
bool: True if the response was handled, False otherwise.
|
|
77
|
+
"""
|
|
78
|
+
|
|
79
|
+
id_ = response_data.get("id", None)
|
|
80
|
+
|
|
81
|
+
if id_ in self._connection_pool.bidi_tasks_containers:
|
|
82
|
+
self._connection_pool.bidi_tasks_containers[id_].response = response_data
|
|
83
|
+
self._connection_pool.bidi_tasks_containers[id_].pending_event.set()
|
|
84
|
+
|
|
85
|
+
return True
|
|
86
|
+
|
|
87
|
+
return False
|
|
88
|
+
|
|
89
|
+
async def _handle_user_prompt_response(self, response_data: Dict[str, Any]) -> bool:
|
|
90
|
+
"""
|
|
91
|
+
Handles user prompt events from BiDi.
|
|
92
|
+
|
|
93
|
+
Args:
|
|
94
|
+
response_data (Dict[str, Any]): The response data from BiDi.
|
|
95
|
+
|
|
96
|
+
Returns:
|
|
97
|
+
bool: True if the response was a user prompt event, False otherwise.
|
|
98
|
+
"""
|
|
99
|
+
|
|
100
|
+
method = response_data.get("method")
|
|
101
|
+
params = response_data.get("params", {})
|
|
102
|
+
|
|
103
|
+
if method == "browsingContext.userPromptOpened":
|
|
104
|
+
context = params.get("context")
|
|
105
|
+
message = params.get("message", "")
|
|
106
|
+
|
|
107
|
+
self._connection_pool.active_prompts[context] = message
|
|
108
|
+
|
|
109
|
+
return True
|
|
110
|
+
|
|
111
|
+
if method == "browsingContext.userPromptClosed":
|
|
112
|
+
context = params.get("context")
|
|
113
|
+
|
|
114
|
+
self._connection_pool.active_prompts.pop(context, None)
|
|
115
|
+
|
|
116
|
+
return True
|
|
117
|
+
|
|
118
|
+
return False
|
|
119
|
+
|
|
120
|
+
async def _handle_response(self, response_data: Dict[str, Any]) -> None:
|
|
121
|
+
"""
|
|
122
|
+
Dispatches BiDi responses to appropriate handlers.
|
|
123
|
+
|
|
124
|
+
Args:
|
|
125
|
+
response_data (Dict[str, Any]): The response data from BiDi.
|
|
126
|
+
"""
|
|
127
|
+
|
|
128
|
+
if await self._handle_user_prompt_response(response_data=response_data):
|
|
129
|
+
return
|
|
130
|
+
|
|
131
|
+
if await self._handle_normal_response(response_data=response_data):
|
|
132
|
+
return
|
|
133
|
+
|
|
134
|
+
async def run(self):
|
|
135
|
+
"""
|
|
136
|
+
Continuously reads messages from the WebSocket and handles them.
|
|
137
|
+
"""
|
|
138
|
+
|
|
139
|
+
while True:
|
|
140
|
+
try:
|
|
141
|
+
message = await self._connection_pool.websocket_connection.get_message()
|
|
142
|
+
response_data: Dict[str, Any] = json.loads(message)
|
|
143
|
+
|
|
144
|
+
await self._handle_response(response_data=response_data)
|
|
145
|
+
except WebSocketEndExceptions:
|
|
146
|
+
break
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
class _TaskHandler:
|
|
150
|
+
"""
|
|
151
|
+
Internal handler for processing W3C tasks and executing BiDi commands.
|
|
152
|
+
"""
|
|
153
|
+
|
|
154
|
+
def __init__(self, connection_pool: "BiDiConnectionPool"):
|
|
155
|
+
"""
|
|
156
|
+
Initializes the task handler.
|
|
157
|
+
|
|
158
|
+
Args:
|
|
159
|
+
connection_pool (BiDiConnectionPool): The parent connection pool.
|
|
160
|
+
"""
|
|
161
|
+
|
|
162
|
+
self._connection_pool = connection_pool
|
|
163
|
+
|
|
164
|
+
def _create_bidi_task_container(self, bidi_request: Dict[str, Any]) -> Tuple[int, BiDiTaskContainer]:
|
|
165
|
+
"""
|
|
166
|
+
Creates a container for a BiDi task.
|
|
167
|
+
|
|
168
|
+
Args:
|
|
169
|
+
bidi_request (Dict[str, Any]): The BiDi request parameters.
|
|
170
|
+
|
|
171
|
+
Returns:
|
|
172
|
+
Tuple[int, BiDiTaskContainer]: The bridge container ID and the task container.
|
|
173
|
+
"""
|
|
174
|
+
|
|
175
|
+
bridge_container_id = next(self._connection_pool.id_generator)
|
|
176
|
+
bidi_task = BiDiTask(
|
|
177
|
+
id=bridge_container_id,
|
|
178
|
+
method=bidi_request["method"],
|
|
179
|
+
params=bidi_request["params"]
|
|
180
|
+
)
|
|
181
|
+
|
|
182
|
+
return bridge_container_id, BiDiTaskContainer(task=bidi_task)
|
|
183
|
+
|
|
184
|
+
async def _send_request_to_bidi(self, bidi_request: Dict[str, Any]) -> Dict[str, Any]:
|
|
185
|
+
"""
|
|
186
|
+
Sends a request to BiDi and waits for the response.
|
|
187
|
+
|
|
188
|
+
Args:
|
|
189
|
+
bidi_request (Dict[str, Any]): The request to send.
|
|
190
|
+
|
|
191
|
+
Returns:
|
|
192
|
+
Dict[str, Any]: The BiDi response.
|
|
193
|
+
"""
|
|
194
|
+
|
|
195
|
+
bridge_container_id, bidi_task_container = self._create_bidi_task_container(bidi_request=bidi_request)
|
|
196
|
+
self._connection_pool.bidi_tasks_containers[bridge_container_id] = bidi_task_container
|
|
197
|
+
|
|
198
|
+
await self._connection_pool.websocket_connection.send_message(json.dumps(bidi_task_container.task.to_dict()))
|
|
199
|
+
await self._connection_pool.bidi_tasks_containers[bridge_container_id].pending_event.wait()
|
|
200
|
+
|
|
201
|
+
bidi_task_container = self._connection_pool.bidi_tasks_containers.pop(bridge_container_id)
|
|
202
|
+
bidi_response = bidi_task_container.response
|
|
203
|
+
|
|
204
|
+
return bidi_response
|
|
205
|
+
|
|
206
|
+
async def _get_normal_response(self, bidi_request: Dict[str, Any]) -> Dict[str, Any]:
|
|
207
|
+
"""
|
|
208
|
+
Handles a general BiDi task.
|
|
209
|
+
|
|
210
|
+
Args:
|
|
211
|
+
bidi_request (Dict[str, Any]): The request parameters.
|
|
212
|
+
|
|
213
|
+
Returns:
|
|
214
|
+
Dict[str, Any]: The BiDi response.
|
|
215
|
+
"""
|
|
216
|
+
|
|
217
|
+
bidi_response = await self._send_request_to_bidi(bidi_request=bidi_request)
|
|
218
|
+
|
|
219
|
+
return bidi_response
|
|
220
|
+
|
|
221
|
+
@staticmethod
|
|
222
|
+
async def _get_uploaded_file(bidi_request: Dict[str, Any]) -> Dict[str, Any]:
|
|
223
|
+
"""
|
|
224
|
+
Handles the task of uploading a file.
|
|
225
|
+
|
|
226
|
+
Args:
|
|
227
|
+
bidi_request (Dict[str, Any]): The BiDi request containing the file data.
|
|
228
|
+
|
|
229
|
+
Returns:
|
|
230
|
+
Dict[str, Any]: The response containing the extracted file path.
|
|
231
|
+
"""
|
|
232
|
+
|
|
233
|
+
return {"result": {"value": unzip_file(base64_zip=bidi_request["file"])}}
|
|
234
|
+
|
|
235
|
+
async def _get_context_user_prompt_text(self, context_id: CURRENT_BROWSING_CONTEXT_TYPEHINT) -> Dict[str, Any]:
|
|
236
|
+
"""
|
|
237
|
+
Handles the task of retrieving text from a user prompt.
|
|
238
|
+
|
|
239
|
+
Args:
|
|
240
|
+
context_id (CURRENT_BROWSING_CONTEXT_TYPEHINT): The ID of the browsing context.
|
|
241
|
+
|
|
242
|
+
Returns:
|
|
243
|
+
Dict[str, Any]: The response containing the prompt text.
|
|
244
|
+
"""
|
|
245
|
+
|
|
246
|
+
text = self._connection_pool.active_prompts.get(context_id, None)
|
|
247
|
+
|
|
248
|
+
if text is None:
|
|
249
|
+
return {"error": "no such alert", "message": "no such alert"}
|
|
250
|
+
|
|
251
|
+
return {"result": {"value": text}}
|
|
252
|
+
|
|
253
|
+
async def _get_task_response(self, bidi_request: Dict[str, Any], w3c_task: W3CTask) -> Dict[str, Any]:
|
|
254
|
+
"""
|
|
255
|
+
Dispatches request to appropriate execution method.
|
|
256
|
+
|
|
257
|
+
Args:
|
|
258
|
+
bidi_request (Dict[str, Any]): The request to execute.
|
|
259
|
+
w3c_task (W3CTask): The original W3C task.
|
|
260
|
+
|
|
261
|
+
Returns:
|
|
262
|
+
Dict[str, Any]: The raw BiDi response.
|
|
263
|
+
"""
|
|
264
|
+
|
|
265
|
+
bidi_method = bidi_request.get("method")
|
|
266
|
+
|
|
267
|
+
if bidi_method == GET_INTERNAL_ALERT_TEXT:
|
|
268
|
+
return await self._get_context_user_prompt_text(context_id=w3c_task.context_id)
|
|
269
|
+
|
|
270
|
+
if bidi_method == UPLOAD_INTERNAL_FILE:
|
|
271
|
+
return await self._get_uploaded_file(bidi_request=bidi_request)
|
|
272
|
+
|
|
273
|
+
return await self._get_normal_response(bidi_request=bidi_request)
|
|
274
|
+
|
|
275
|
+
async def _handle_request(self, bidi_request: Dict[str, Any], w3c_task: W3CTask) -> Dict[str, Any]:
|
|
276
|
+
"""
|
|
277
|
+
Executes BiDi request and maps it back to W3C response.
|
|
278
|
+
|
|
279
|
+
Args:
|
|
280
|
+
bidi_request (Dict[str, Any]): The mapped BiDi request.
|
|
281
|
+
w3c_task (W3CTask): The original W3C task.
|
|
282
|
+
|
|
283
|
+
Returns:
|
|
284
|
+
Dict[str, Any]: The W3C-compatible response.
|
|
285
|
+
"""
|
|
286
|
+
|
|
287
|
+
bidi_response = await self._get_task_response(bidi_request=bidi_request, w3c_task=w3c_task)
|
|
288
|
+
|
|
289
|
+
if "error" in bidi_response:
|
|
290
|
+
return redirect_error_response(command=w3c_task.command, bidi_response=bidi_response)
|
|
291
|
+
|
|
292
|
+
return map_response(
|
|
293
|
+
command=w3c_task.command,
|
|
294
|
+
bidi_result=bidi_response["result"],
|
|
295
|
+
request_params=w3c_task.params
|
|
296
|
+
)
|
|
297
|
+
|
|
298
|
+
async def _handle_task(self, w3c_task_container: W3CTaskContainer):
|
|
299
|
+
"""
|
|
300
|
+
Processes a W3C task by mapping it to BiDi and executing it.
|
|
301
|
+
|
|
302
|
+
Args:
|
|
303
|
+
w3c_task_container (W3CTaskContainer): The container of the W3C task to process.
|
|
304
|
+
"""
|
|
305
|
+
|
|
306
|
+
try:
|
|
307
|
+
w3c_task = w3c_task_container.task
|
|
308
|
+
|
|
309
|
+
bidi_request = map_request(
|
|
310
|
+
command=w3c_task.command,
|
|
311
|
+
params=w3c_task.params,
|
|
312
|
+
context_id=w3c_task.context_id
|
|
313
|
+
)
|
|
314
|
+
|
|
315
|
+
w3c_task_container.response["response"] = await self._handle_request(bidi_request=bidi_request, w3c_task=w3c_task)
|
|
316
|
+
except Exception as exception:
|
|
317
|
+
w3c_task_container.response["error"] = exception
|
|
318
|
+
finally:
|
|
319
|
+
w3c_task_container.pending_event.set()
|
|
320
|
+
|
|
321
|
+
async def run(self) -> None:
|
|
322
|
+
"""
|
|
323
|
+
Processes W3C tasks from the receive channel.
|
|
324
|
+
"""
|
|
325
|
+
|
|
326
|
+
try:
|
|
327
|
+
async for w3c_task_container in self._connection_pool.task_receive_channel:
|
|
328
|
+
self._connection_pool.nursery.start_soon(self._handle_task, w3c_task_container)
|
|
329
|
+
except WebSocketEndExceptions:
|
|
330
|
+
pass
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
class BiDiConnectionPool:
|
|
334
|
+
"""
|
|
335
|
+
Manages a pool of connections and tasks for BiDi communication.
|
|
336
|
+
"""
|
|
337
|
+
|
|
338
|
+
def __init__(self, websocket_url: str, buffer_size: Union[int, float] = math.inf):
|
|
339
|
+
"""
|
|
340
|
+
Initializes the BiDiConnectionPool.
|
|
341
|
+
|
|
342
|
+
Args:
|
|
343
|
+
websocket_url (str): The URL of the WebSocket server.
|
|
344
|
+
buffer_size (Union[int, float]): The size of the task buffer.
|
|
345
|
+
"""
|
|
346
|
+
|
|
347
|
+
self._websocket_url = websocket_url
|
|
348
|
+
self._buffer_size = buffer_size
|
|
349
|
+
self._websocket_connection: Optional[WebSocketConnection] = None
|
|
350
|
+
self._nursery: Optional[trio.Nursery] = None
|
|
351
|
+
self._exit_stack = AsyncExitStack()
|
|
352
|
+
self._task_send_channel: Optional[trio.MemorySendChannel[W3CTaskContainer]] = None
|
|
353
|
+
self._task_receive_channel: Optional[trio.MemoryReceiveChannel[W3CTaskContainer]] = None
|
|
354
|
+
self._id_generator: Optional[itertools.count[int]] = None
|
|
355
|
+
self._bidi_tasks_containers: Dict[int, BiDiTaskContainer] = {}
|
|
356
|
+
self._active_prompts: Dict[str, str] = {}
|
|
357
|
+
self._is_active = False
|
|
358
|
+
|
|
359
|
+
self._task_handler = _TaskHandler(connection_pool=self)
|
|
360
|
+
|
|
361
|
+
self._response_handler = _WebsocketResponseHandler(connection_pool=self)
|
|
362
|
+
|
|
363
|
+
async def start(self) -> trio.MemorySendChannel[W3CTaskContainer]:
|
|
364
|
+
"""
|
|
365
|
+
Starts the connection pool and internal loops.
|
|
366
|
+
|
|
367
|
+
Returns:
|
|
368
|
+
trio.MemorySendChannel[W3CTaskContainer]: The channel to send tasks to.
|
|
369
|
+
"""
|
|
370
|
+
|
|
371
|
+
if self._is_active:
|
|
372
|
+
return self._task_send_channel
|
|
373
|
+
|
|
374
|
+
self._websocket_connection = await self._exit_stack.enter_async_context(open_websocket_url(self._websocket_url))
|
|
375
|
+
self._nursery = await self._exit_stack.enter_async_context(trio.open_nursery())
|
|
376
|
+
|
|
377
|
+
self._task_send_channel, self._task_receive_channel = trio.open_memory_channel(max_buffer_size=self._buffer_size)
|
|
378
|
+
|
|
379
|
+
self._nursery.start_soon(self._task_handler.run)
|
|
380
|
+
self._nursery.start_soon(self._response_handler.run)
|
|
381
|
+
|
|
382
|
+
self._id_generator = itertools.count(1)
|
|
383
|
+
self._is_active = True
|
|
384
|
+
|
|
385
|
+
return self._task_send_channel
|
|
386
|
+
|
|
387
|
+
async def __aenter__(self) -> trio.MemorySendChannel[W3CTaskContainer]:
|
|
388
|
+
"""
|
|
389
|
+
Async context manager entry.
|
|
390
|
+
|
|
391
|
+
Returns:
|
|
392
|
+
trio.MemorySendChannel[W3CTaskContainer]: The task send channel.
|
|
393
|
+
"""
|
|
394
|
+
|
|
395
|
+
return await self.start()
|
|
396
|
+
|
|
397
|
+
async def stop(self) -> None:
|
|
398
|
+
"""
|
|
399
|
+
Stops the connection pool and cleans up resources.
|
|
400
|
+
"""
|
|
401
|
+
|
|
402
|
+
@log_on_error
|
|
403
|
+
async def _close_channels() -> None:
|
|
404
|
+
"""
|
|
405
|
+
Closes the task send and receive memory channels.
|
|
406
|
+
"""
|
|
407
|
+
|
|
408
|
+
if self._task_send_channel is not None:
|
|
409
|
+
try:
|
|
410
|
+
await self._task_send_channel.aclose()
|
|
411
|
+
except TrioEndExceptions:
|
|
412
|
+
pass
|
|
413
|
+
|
|
414
|
+
self._task_send_channel = None
|
|
415
|
+
|
|
416
|
+
if self._task_receive_channel is not None:
|
|
417
|
+
try:
|
|
418
|
+
await self._task_receive_channel.aclose()
|
|
419
|
+
except TrioEndExceptions:
|
|
420
|
+
pass
|
|
421
|
+
|
|
422
|
+
self._task_receive_channel = None
|
|
423
|
+
|
|
424
|
+
@log_on_error
|
|
425
|
+
async def _close_bidi_tasks() -> None:
|
|
426
|
+
"""
|
|
427
|
+
Cleans up pending BiDi tasks by setting a stop error and clearing the containers.
|
|
428
|
+
"""
|
|
429
|
+
|
|
430
|
+
if exc_type is not None or exc_value is not None or exc_traceback is not None:
|
|
431
|
+
reason = "".join(traceback.format_exception(exc_type, exc_value, exc_traceback))
|
|
432
|
+
else:
|
|
433
|
+
reason = "BiDi connection pool stopped"
|
|
434
|
+
|
|
435
|
+
for container in self._bidi_tasks_containers.values():
|
|
436
|
+
if not container.pending_event.is_set():
|
|
437
|
+
container.response["error"] = BiDiBridgeStoppedError(reason=reason)
|
|
438
|
+
container.pending_event.set()
|
|
439
|
+
|
|
440
|
+
self._bidi_tasks_containers.clear()
|
|
441
|
+
|
|
442
|
+
@log_on_error
|
|
443
|
+
async def _close_async_stack() -> None:
|
|
444
|
+
"""
|
|
445
|
+
Closes the asynchronous resource stack.
|
|
446
|
+
"""
|
|
447
|
+
|
|
448
|
+
if self._nursery is not None:
|
|
449
|
+
try:
|
|
450
|
+
self._nursery.cancel_scope.cancel()
|
|
451
|
+
except TrioEndExceptions:
|
|
452
|
+
pass
|
|
453
|
+
|
|
454
|
+
self._nursery = None
|
|
455
|
+
|
|
456
|
+
if self._websocket_connection is not None:
|
|
457
|
+
try:
|
|
458
|
+
await self._websocket_connection.aclose()
|
|
459
|
+
except TrioEndExceptions:
|
|
460
|
+
pass
|
|
461
|
+
|
|
462
|
+
self._websocket_connection = None
|
|
463
|
+
|
|
464
|
+
try:
|
|
465
|
+
await self._exit_stack.aclose()
|
|
466
|
+
except TrioEndExceptions:
|
|
467
|
+
pass
|
|
468
|
+
except AssertionError:
|
|
469
|
+
pass # TODO solve exit issue
|
|
470
|
+
|
|
471
|
+
exc_type, exc_value, exc_traceback = sys.exc_info()
|
|
472
|
+
|
|
473
|
+
if not self._is_active:
|
|
474
|
+
return
|
|
475
|
+
|
|
476
|
+
await _close_channels()
|
|
477
|
+
await _close_bidi_tasks()
|
|
478
|
+
await _close_async_stack()
|
|
479
|
+
|
|
480
|
+
self._active_prompts.clear()
|
|
481
|
+
self._id_generator = None
|
|
482
|
+
self._is_active = False
|
|
483
|
+
|
|
484
|
+
async def __aexit__(
|
|
485
|
+
self,
|
|
486
|
+
exc_type: Optional[Type[BaseException]],
|
|
487
|
+
exc_val: Optional[BaseException],
|
|
488
|
+
exc_tb: Optional[TracebackType],
|
|
489
|
+
) -> bool:
|
|
490
|
+
"""
|
|
491
|
+
Asynchronously exits the BiDi connection pool context.
|
|
492
|
+
|
|
493
|
+
Args:
|
|
494
|
+
exc_type (Optional[Type[BaseException]]): The exception type, if any.
|
|
495
|
+
exc_val (Optional[BaseException]): The exception value, if any.
|
|
496
|
+
exc_tb (Optional[TracebackType]): The exception traceback, if any.
|
|
497
|
+
|
|
498
|
+
Returns:
|
|
499
|
+
bool: True if an exception was suppressed, False otherwise.
|
|
500
|
+
"""
|
|
501
|
+
|
|
502
|
+
await self.stop()
|
|
503
|
+
|
|
504
|
+
if exc_type is not None and exc_val is not None and exc_tb is not None:
|
|
505
|
+
return True
|
|
506
|
+
|
|
507
|
+
return False
|
|
508
|
+
|
|
509
|
+
@property
|
|
510
|
+
def active_prompts(self) -> Dict[str, str]:
|
|
511
|
+
"""
|
|
512
|
+
Returns the map of active prompts.
|
|
513
|
+
"""
|
|
514
|
+
|
|
515
|
+
return self._active_prompts
|
|
516
|
+
|
|
517
|
+
@property
|
|
518
|
+
def bidi_tasks_containers(self) -> Dict[int, BiDiTaskContainer]:
|
|
519
|
+
"""
|
|
520
|
+
Returns the active BiDi tasks.
|
|
521
|
+
"""
|
|
522
|
+
|
|
523
|
+
return self._bidi_tasks_containers
|
|
524
|
+
|
|
525
|
+
@property
|
|
526
|
+
def buffer_size(self) -> Union[int, float]:
|
|
527
|
+
"""
|
|
528
|
+
Returns the buffer size.
|
|
529
|
+
"""
|
|
530
|
+
|
|
531
|
+
return self._buffer_size
|
|
532
|
+
|
|
533
|
+
@property
|
|
534
|
+
def id_generator(self) -> Optional[itertools.count]:
|
|
535
|
+
"""
|
|
536
|
+
Returns the task ID generator.
|
|
537
|
+
"""
|
|
538
|
+
|
|
539
|
+
return self._id_generator
|
|
540
|
+
|
|
541
|
+
@property
|
|
542
|
+
def is_active(self) -> bool:
|
|
543
|
+
"""
|
|
544
|
+
Returns the activation status.
|
|
545
|
+
"""
|
|
546
|
+
|
|
547
|
+
return self._is_active
|
|
548
|
+
|
|
549
|
+
@property
|
|
550
|
+
def nursery(self) -> Optional[trio.Nursery]:
|
|
551
|
+
"""
|
|
552
|
+
Returns the internal nursery.
|
|
553
|
+
"""
|
|
554
|
+
|
|
555
|
+
return self._nursery
|
|
556
|
+
|
|
557
|
+
@property
|
|
558
|
+
def task_receive_channel(self) -> trio.MemoryReceiveChannel[W3CTaskContainer]:
|
|
559
|
+
"""
|
|
560
|
+
Returns the task receive channel.
|
|
561
|
+
"""
|
|
562
|
+
|
|
563
|
+
return self._task_receive_channel
|
|
564
|
+
|
|
565
|
+
@property
|
|
566
|
+
def task_send_channel(self) -> trio.MemorySendChannel[W3CTaskContainer]:
|
|
567
|
+
"""
|
|
568
|
+
Returns the task send channel.
|
|
569
|
+
"""
|
|
570
|
+
|
|
571
|
+
return self._task_send_channel
|
|
572
|
+
|
|
573
|
+
@property
|
|
574
|
+
def websocket_connection(self) -> Optional[WebSocketConnection]:
|
|
575
|
+
"""
|
|
576
|
+
Returns the current WebSocket connection.
|
|
577
|
+
"""
|
|
578
|
+
|
|
579
|
+
return self._websocket_connection
|
|
580
|
+
|
|
581
|
+
@property
|
|
582
|
+
def websocket_url(self) -> str:
|
|
583
|
+
"""
|
|
584
|
+
Returns the WebSocket URL.
|
|
585
|
+
"""
|
|
586
|
+
|
|
587
|
+
return self._websocket_url
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from selenium.webdriver.common.by import By
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
__all__ = ["BY_MAPPING_DICT"]
|
|
5
|
+
|
|
6
|
+
BY_MAPPING_DICT = {
|
|
7
|
+
By.CSS_SELECTOR: "css",
|
|
8
|
+
By.ID: "css",
|
|
9
|
+
By.XPATH: "xpath",
|
|
10
|
+
By.LINK_TEXT: "linkText",
|
|
11
|
+
By.PARTIAL_LINK_TEXT: "partialLinkText",
|
|
12
|
+
By.TAG_NAME: "css",
|
|
13
|
+
By.CLASS_NAME: "css"
|
|
14
|
+
}
|