Repository navigation
Browser Handlers
The browsers_handler package provides high-level utilities to detect, identify, and parse information about web browsers installed on the local system.
By automating the discovery of browser executable paths and version numbers, osn-selenium eliminates the need for users to manually provide file paths in most scenarios. This is especially critical for the framework to correctly match the Chrome DevTools Protocol (CDP) version with the running browser.
All detected browsers are represented by a standardized data structure defined in osn_selenium/browsers_handler/models.py.
A strict DictModel containing essential information:
-
name: The display name of the browser (e.g., "Google Chrome", "Yandex"). -
path: Apathlib.Pathobject pointing to the browser's executable binary. -
version: The exact version string of the browser.
The package uses a modular approach to handle environment differences between Windows and Linux.
-
Registry Scanning: Queries the Windows Registry at
SOFTWARE\Clients\StartMenuInternetto find registered browsers. -
Version Extraction: Uses the
win32api(GetFileVersionInfo) to extract metadata directly from the.exebinary, providing the most accurate versioning. -
WebDriver Versioning: Executes the WebDriver binary with the
--versionflag and parses the output using regex.
-
Desktop Files: Scans standard directories like
/usr/share/applicationsfor.desktopfiles associated with theWebBrowsercategory. -
Binary Discovery: Looks for known binary names (e.g.,
google-chrome-stable,microsoft-edge-dev,yandex-browser) in the system PATH usingshutil.which. -
CLI Parsing: Executes the found binaries with the
--versionflag to extract the version string via regex.
The osn_selenium/browsers_handler/__init__.py module exposes a simple, cross-platform interface.
Scans the system and returns a list of all detected Browser objects.
from osn_selenium.browsers_handler import get_installed_browsers
browsers = get_installed_browsers()
for b in browsers:
print(f"Found {b.name} (v{b.version}) at {b.path}")Searches for a specific browser by name and returns its pathlib.Path.
from osn_selenium.browsers_handler import get_path_to_browser
chrome_path = get_path_to_browser("Google Chrome")Retrieves the version string of an installed browser.
from osn_selenium.browsers_handler import get_version_of_browser
version = get_version_of_browser("Yandex")Parses the version of a specific WebDriver executable (e.g., chromedriver or msedgedriver).
from osn_selenium.browsers_handler import get_version_of_driver
drv_version = get_version_of_driver("./chromedriver.exe")