An advanced, asynchronous wrapper for Selenium designed for fine-grained browser control. It leverages `trio` for async operations, provides human-like action chains for more natural automation, and offers deep integration with the Chrome DevTools Protocol (CDP) for advanced features like network interception. The library is structured to be extensible, with built-in support for Blink-based browsers like Chrome, Edge, and Yandex.
Project description
osn-selenium: Advanced Selenium Wrapper with Async Support and Fingerprinting Protection
osn-selenium is a robust wrapper around Selenium WebDriver designed for automation of Blink-based browsers (Chrome, Edge, Yandex). It extends standard Selenium capabilities by providing native asynchronous support via Trio, deep integration with the Chrome DevTools Protocol (CDP), sophisticated browser fingerprint spoofing, and human-like user interaction simulation.
For more detailed information, please visit the wiki page.
Technologies
Key Features
- Dual Operation Modes:
- Synchronous: Standard blocking execution similar to vanilla Selenium.
- Asynchronous (Trio): Fully async implementation allowing concurrent control of browser targets using the Trio library.
- Deep CDP Integration:
- Direct access to Chrome DevTools Protocol domains (Network, Page, DOM, Security, etc.).
- Event listening and handling (e.g., intercepting network requests, console logs).
- Advanced Fingerprint Spoofing:
FingerprintSettingsmodule to inject scripts detecting and modifying browser fingerprints.- Spoofing capabilities for Canvas, WebGL, AudioContext, Fonts, Screen properties, and more.
- Configurable noise generation (static or random) to evade anti-bot detection.
- Human-Like Interactions:
HumanLikeActionChainssimulating natural mouse movements (Bezier curves, deviations) and typing speeds.- Smooth scrolling algorithms.
- Browser Lifecycle Management:
- Auto-detection of installed browsers (Chrome, Edge, Yandex).
- Robust handling of browser processes, including zombie process cleanup and port management.
- Structured management of browser flags, arguments, and experimental options.
- Enhanced Element Interaction:
- Wrappers for WebElements, ShadowRoots, and Alerts with additional utility methods.
- Built-in JavaScript execution helpers for viewport checks and geometry retrieval.
Installation
-
Install library:
-
With pip:
pip install osn-selenium
With pip (beta versions):
pip install -i https://test.pypi.org/simple/ osn_system_utils
-
With git:
pip install git+https://github.com/oddshellnick/osn-selenium.git
(Ensure you have git installed)
-
With git (beta versions):
pip install git+https://github.com/oddshellnick/osn-selenium.git@dev
(Ensure you have git installed)
-
-
Install the required Python packages using pip:
pip install -r requirements.txt
Usage
Here are some examples of how to use osn-selenium:
Synchronous Chrome with Human-Like Actions
from osn_selenium.webdrivers.sync.chrome import ChromeWebDriver
from osn_selenium.models import WindowRect
# Initialize driver with specific window size
driver = ChromeWebDriver(
webdriver_path="webdriver.exe",
window_rect=WindowRect(width=1280, height=720)
)
try:
driver.start_webdriver()
driver.get("https://google.com")
# Locate search bar
search_bar = driver.find_element(by="name", value="q")
# Use HumanLikeActionChains for natural typing
actions = driver.action_chains()
actions.hm_move_to_element(search_bar)
actions.click()
actions.hm_text_input("Selenium automation")
actions.perform()
finally:
driver.quit()
Asynchronous (Trio) with Fingerprint Spoofing
import trio
from osn_selenium.webdrivers.trio_threads.chrome import ChromeWebDriver
from osn_selenium.dev_tools.settings import DevToolsSettings
from osn_selenium.javascript.fingerprint import FingerprintSettings
async def main():
# Configure fingerprint spoofing
fp_settings = FingerprintSettings(
optimize_events=True,
# Detect and spoof specific APIs
use_preset_registry=True
)
# Configure DevTools
dt_settings = DevToolsSettings(
fingerprint_settings=fp_settings
)
driver = ChromeWebDriver(
webdriver_path="webdriver.exe",
devtools_settings=dt_settings
)
try:
await driver.start_webdriver()
# Start DevTools session to inject spoofing scripts
async with driver.devtools:
await driver.get("https://browserleaks.com/canvas")
await trio.sleep(10) # Let the page load and scripts run
finally:
await driver.quit()
trio.run(main)
Classes and Functions
WebDrivers (osn_selenium.webdrivers)
This package contains the main entry points for initializing browser automation. It is split into sync and trio_threads subpackages.
CoreWebDriver- Base class aggregating all mixins (Actions, Auth, Capture, CDP, Elements, File, Lifecycle, Navigation, Script, Settings, Storage, Timeouts, Window).
ChromeWebDriver(Available insyncandtrio_threads)__init__(...): Initializes the Chrome driver with paths, flags managers, and timeout settings.start_webdriver(...): Starts the browser process and the WebDriver session.quit(): Closes the browser and session.
EdgeWebDriver(Available insyncandtrio_threads)- Specialized WebDriver for Microsoft Edge.
YandexWebDriver(Available insyncandtrio_threads)- Specialized WebDriver for Yandex Browser.
Browser Flags (osn_selenium.flags)
Manages configuration for browser launch arguments and capabilities.
BrowserFlagsManagerset_argument(argument, value): Sets a command-line argument.set_experimental_option(option, value): Sets a WebDriver experimental option.build_options_arguments(options): Applies arguments to the Selenium Options object.
ChromeFlagsManager/EdgeFlagsManager/YandexFlagsManager- Subclasses with specific default flags and binary detection logic for their respective browsers.
DevTools Protocol (osn_selenium.dev_tools)
Manages the connection to Chrome DevTools Protocol for low-level control.
DevToolsrun(): Initializes the BiDi connection and starts event listeners.stop(...): Cleans up resources and closes connections.
DevToolsTarget- Represents a specific target (tab/page) being controlled.
CDPExecutor(Available inexecutors.sync.cdpandexecutors.trio_threads.cdp)execute(cmd, cmd_args): Sends a raw CDP command.network: Access toNetworkdomain commands (cookies, cache, interception).page: Access toPagedomain commands (navigation, printing, screenshots).dom: Access toDOMdomain commands.emulation: Access toEmulationdomain (device metrics, user agent, sensors).- (Includes accessors for all mapped CDP domains like Fetch, Storage, Runtime, etc.)
Instances Wrappers (osn_selenium.instances)
Wrappers around standard Selenium objects to provide enhanced functionality or async compatibility.
WebElementclick(): Clicks the element.send_keys(...): Types into the element.screenshot(filename): Takes a screenshot of the specific element.find_element(...): Finds a child element.
ActionChains/HumanLikeActionChainshm_move_to_element(...): Moves mouse to element using human-like curves.hm_text_input(...): Types text with random delays between keystrokes.hm_scroll(...): Scrolls the page smoothly.
ShadowRootfind_element(...): Finds elements inside a Shadow DOM.
Javascript & Fingerprinting (osn_selenium.javascript)
Utilities for executing JS and managing browser fingerprints.
FingerprintSettingsgenerate_js(): Creates the injection script for fingerprint spoofing based on the registry configuration.
JSExecutorexecute(script, ...): Executes raw JavaScript.check_element_in_viewport(element): Returns True if element is visible in viewport.get_element_rect_in_viewport(element): Returns element coordinates relative to viewport.
Notes
- CDP Versioning and External Packages:
This library supports a modular CDP (Chrome DevTools Protocol) architecture. Since standard Selenium distributions often deprecate or remove older protocol versions, we maintain a dedicated repository for all versions at osn-selenium-cdp.
- Manual Installation: You can install specific CDP support by targeting the corresponding branch (e.g.,
pip install git+https://github.com/oddshellnick/osn-selenium-cdp.git@v131). - Structure Requirement: If you choose to add or create CDP version packages manually, they must strictly follow the directory structure used in the
osn-selenium-cdprepository. This ensures that the internalMetaPathFinderhook can correctly intercept and redirect imports fromselenium.webdriver.common.devtools. Deviating from this structure will result inCDPPackageErrororImportError.
- Manual Installation: You can install specific CDP support by targeting the corresponding branch (e.g.,
- Concurrency Constraints in
trio_threads: Thetrio_threadsimplementation is built using a unifiedtrio.Lock. This means that every driver function and every associated instance (includingActionChains,WebElement,Alert, etc.) can execute only one operation at a time. Do not attempt to parallelize multiple operations (coroutines) within a single browser instance, as they will be queued sequentially. The primary purpose of this asynchronous implementation is to enable the simultaneous management of multiple browser instances within a single event loop, rather than concurrent interactions with one browser. - CDP Domains and Background Tasks:
When configuring the domains for network interception, it is highly recommended to provide a
target_background_taskin yourDevToolsSettings. This is especially critical for websites that dynamically create numerous targets (such as iframes or workers). Without a proper background task to handle these events, the browser's execution flow might hang or fail to process requests for nested targets properly. - Experimental
trio_bidiArchitecture: A new experimental architecture,trio_bidi, has been introduced. While it currently does not cover 100% of browser capabilities, it supports all core functionalities, including page navigation and element interactions, through native BiDi communication.
Future Notes
- Hybrid Composition Support: We are preparing to expose all mixin-based functionality as distinct attributes within
CoreWebDriverandBlinkWebDriver(e.g.,driver.navigation.get(),driver.storage.add_cookie()). This will provide a cleaner, more modular alternative to the flat API while maintaining 100% backward compatibility with standard Selenium-like calls. - Firefox (GeckoDriver) Support: Implementation of Gecko-specific flags and full BiDi/CDP integration for Firefox.
- macOS Support: Extending browser auto-detection and lifecycle management for macOS environments.
- High-Level CDP Handlers: Expanding the
dev_tools.domainsmodule to include simplified event-driven logic forNetwork,Page, andRuntimedomains, similar to the currentFetchimplementation. - Enhanced Human-Like Actions: Adding more complex Bezier-based mouse movement patterns and advanced typing jitter to further decrease automation footprints.
- Full BiDi Coverage: Implementing comprehensive Selenium feature coverage using BiDi mappings to eventually replace the need for synchronous thread pools in async mode.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file osn_selenium-1.2.0.tar.gz.
File metadata
- Download URL: osn_selenium-1.2.0.tar.gz
- Upload date:
- Size: 236.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6295567b844e89706b6296a8092f920c55484ec0ed48054472a80876c6c2de8d
|
|
| MD5 |
3ebc9157fd1e117d72a7d392453a0e89
|
|
| BLAKE2b-256 |
74eb326f61c0d52d60ac437563ec290b4db9d7bea57ce58a98e4c42284b8377d
|
Provenance
The following attestation bundles were made for osn_selenium-1.2.0.tar.gz:
Publisher:
python-publish.yml on oddshellnick/osn-selenium
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
osn_selenium-1.2.0.tar.gz -
Subject digest:
6295567b844e89706b6296a8092f920c55484ec0ed48054472a80876c6c2de8d - Sigstore transparency entry: 910061081
- Sigstore integration time:
-
Permalink:
oddshellnick/osn-selenium@e1d1b6140d65cbefe4caf4d556812c472779d580 -
Branch / Tag:
refs/tags/v1.2.0 - Owner: https://github.com/oddshellnick
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@e1d1b6140d65cbefe4caf4d556812c472779d580 -
Trigger Event:
release
-
Statement type:
File details
Details for the file osn_selenium-1.2.0-py3-none-any.whl.
File metadata
- Download URL: osn_selenium-1.2.0-py3-none-any.whl
- Upload date:
- Size: 468.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d8364ff6606b58c15225f80b80d82bdf20175139df510040e3144f0e7c54aeb
|
|
| MD5 |
47dfdcd0a66337625a61b5cf90045964
|
|
| BLAKE2b-256 |
2af84026cfc15d240bbcf44271b8785e370f3116467427df086f0552adf7346a
|
Provenance
The following attestation bundles were made for osn_selenium-1.2.0-py3-none-any.whl:
Publisher:
python-publish.yml on oddshellnick/osn-selenium
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
osn_selenium-1.2.0-py3-none-any.whl -
Subject digest:
2d8364ff6606b58c15225f80b80d82bdf20175139df510040e3144f0e7c54aeb - Sigstore transparency entry: 910061098
- Sigstore integration time:
-
Permalink:
oddshellnick/osn-selenium@e1d1b6140d65cbefe4caf4d556812c472779d580 -
Branch / Tag:
refs/tags/v1.2.0 - Owner: https://github.com/oddshellnick
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@e1d1b6140d65cbefe4caf4d556812c472779d580 -
Trigger Event:
release
-
Statement type: