Repository navigation
osn-selenium v1.2.0 - The BiDi Bridge & Architecture Expansion
This release marks a significant milestone in the library's evolution with the introduction of the experimental trio_bidi architecture. This new mode moves away from thread-based wrapping and implements a native asynchronous driver that communicates directly with the browser via the WebDriver BiDi protocol over WebSockets. Additionally, this update brings substantial refactoring to the DevTools manager, improves lifecycle management across all architectures, and enhances the robustness of Trio thread synchronization.
Key Improvements in v1.2.0:
-
New Experimental Architecture:
trio_bidi
A completely new driver architecture has been introduced. Unliketrio_threads, which runs synchronous Selenium commands in a thread pool,trio_bidiestablishes a direct BiDi session.- Native Async: Operations are handled via
triotasks and WebSockets without blocking threads. - BiDi Bridge: Implements a mapping layer that converts standard W3C WebDriver commands into BiDi protocol commands and maps the responses back to W3C format.
- Connection Pool: Features a robust
BiDiConnectionPoolto manage WebSocket messages and task dispatching. - Note: This architecture is currently experimental and may not cover 100% of the W3C spec yet.
- Native Async: Operations are handled via
-
Refactored DevTools Lifecycle Management
TheDevToolsmanager and its associated lifecycles have been overhauled for better stability.- AsyncExitStack: Adopted
contextlib.AsyncExitStackfor more reliable resource cleanup (connections, nurseries) during shutdown. - Robust Error Handling: Improved handling of connection interruptions (
WebSocketEndExceptions,TrioEndExceptions) to prevent "zombie" processes or hanging tasks. - Moved Utilities: General utility decorators and exception helpers have been moved from
osn_selenium.dev_toolsto the rootosn_seleniumpackage for broader usage.
- AsyncExitStack: Adopted
-
Enhanced Trio Threads Synchronization
The core logic for wrapping synchronous calls in asynchronous environments has been upgraded.- Context Variable Exchange: The
sync_to_triohelper now supports exchanging context variables between the main Trio loop and the worker threads, ensuring execution context is preserved. - Unified Locking: Logic for
trio.LockandCapacityLimiterhas been centralized in the new_trio_threads_helpers.pymodule.
- Context Variable Exchange: The
-
Standardized WebDriver Lifecycle
The start and stop sequences for WebDrivers have been standardized acrosssync,trio_threads, andtrio_bidi.- Stop vs. Close:
stop_webdriveris now the standard method for terminating sessions, ensuring consistency in how drivers are torn down. - Context Managers: Updated
__enter__and__aenter__implementations to ensurestart_webdriverandstop_webdriverare called correctly, making usage withinwithandasync withblocks more reliable.
- Stop vs. Close:
-
Exception Hierarchy Refinement
- BiDi Exceptions: Introduced specific exceptions for the new architecture, such as
BiDiBridgeError,CommandNotMappedToBiDiError, andBiDiExecutionError. - Exception Wrappers: The
ExceptionThrownwrapper is now available inosn_selenium.exceptions.baseto help manage exceptions returned from background tasks without crashing the event loop immediately.
- BiDi Exceptions: Introduced specific exceptions for the new architecture, such as
Putting It All Together:
v1.2.0 is a foundational release that lays the groundwork for a truly asynchronous future for osn-selenium. While users can continue to rely on the stable trio_threads implementation, the new trio_bidi architecture offers a glimpse into higher-performance, non-blocking browser automation. Coupled with stricter lifecycle management and cleaner internal organization, this update improves the library's stability and extensibility.