Skip to content

Browser Handlers

Eduard Dik edited this page Jan 30, 2026 · 1 revision

Browser Handlers Overview

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.


The Browser Model

All detected browsers are represented by a standardized data structure defined in osn_selenium/browsers_handler/models.py.

Browser Model

A strict DictModel containing essential information:

  • name: The display name of the browser (e.g., "Google Chrome", "Yandex").
  • path: A pathlib.Path object pointing to the browser's executable binary.
  • version: The exact version string of the browser.

Platform-Specific Detection

The package uses a modular approach to handle environment differences between Windows and Linux.

Windows Detection (osn_selenium/browsers_handler/_windows.py)

  • Registry Scanning: Queries the Windows Registry at SOFTWARE\Clients\StartMenuInternet to find registered browsers.
  • Version Extraction: Uses the win32api (GetFileVersionInfo) to extract metadata directly from the .exe binary, providing the most accurate versioning.
  • WebDriver Versioning: Executes the WebDriver binary with the --version flag and parses the output using regex.

Linux Detection (osn_selenium/browsers_handler/_linux.py)

  • Desktop Files: Scans standard directories like /usr/share/applications for .desktop files associated with the WebBrowser category.
  • Binary Discovery: Looks for known binary names (e.g., google-chrome-stable, microsoft-edge-dev, yandex-browser) in the system PATH using shutil.which.
  • CLI Parsing: Executes the found binaries with the --version flag to extract the version string via regex.

Public API

The osn_selenium/browsers_handler/__init__.py module exposes a simple, cross-platform interface.

get_installed_browsers()

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}")

get_path_to_browser(browser_name)

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")

get_version_of_browser(browser_name)

Retrieves the version string of an installed browser.

from osn_selenium.browsers_handler import get_version_of_browser

version = get_version_of_browser("Yandex")

get_version_of_driver(driver_path)

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")

Clone this wiki locally