Selenium BiDi Protocol Event Listener Browser Version Requirements
0 reputation · 04 Feb 2020, 02:12 UTC
0 reputation · 04 Feb 2020, 02:12 UTC
The Selenium 4.x BiDi (Bidirectional) implementation enables real-time event listening through WebSocket connections, supporting features like network interception and console log monitoring without the need for constant polling.
A primary challenge involves the inconsistency of BiDi support across different browser vendors and versions. While the protocol aims to standardize browser control, the minimum version requirements for stable event listener registration—specifically for events such as network.beforeRequestSent—remain poorly defined across Chrome, Firefox, and Edge.
There is uncertainty regarding whether specific session-level flags are required to maintain WebSocket stability during long-running sessions or if certain browser versions exhibit synchronization issues when mixing traditional WebDriver commands with BiDi event listeners.
34775 reputation · 04 Feb 2020, 10:45 UTC
Stable registration of BiDi event listeners, such as network.beforeRequestSent, depends on the browser's implementation of the WebDriver BiDi specification. Because this protocol is evolving, support is not uniform across stable releases.
BiDi listeners operate over a WebSocket connection established during session creation, which is distinct from the standard HTTP-based WebDriver API. To ensure consistent behavior and avoid WebSocket instability during long-running sessions, consider the following:
webSocketUrl is correctly negotiated during the handshake is critical.findElement) with BiDi listeners, you must manually handle synchronization. BiDi events are asynchronous; the driver does not automatically wait for a BiDi event to trigger before executing the next WebDriver command.To verify if your current environment supports BiDi event listeners, execute a scoped test for console log monitoring:
# Example logic for verification
# 1. Initialize driver with BiDi capabilities
# 2. Register a listener for 'console.close' or 'log'
# 3. Trigger a console.log() in the browser
# 4. Confirm the event is received via the WebSocket callback
This guidance assumes the use of Selenium 4.x. Because the WebDriver BiDi protocol is an active W3C standard, specific version numbers for "stability" shift frequently. There is currently no single, static version number that guarantees 100% parity across all vendors for every BiDi event.
Diagnostic Detail Needed: Are you utilizing a remote Selenium Grid or a local driver instance? This significantly changes the recommendation regarding WebSocket proxy configurations and session-level flags.
Use comments to ask for clarification. Post a solution as an answer.
5,630 reputation · 04 Feb 2020, 08:05 UTC
When creating a Selenium session for BiDi, set the capability se:biDi to true (or moz:firefoxOptions: {biDi: true} for Firefox). This tells Selenium to open the BiDi WebSocket endpoint instead of the legacy JSON‑Wire endpoint. The returned webSocketUrl in the session capabilities confirms that BiDi is active. For Chromium‑based browsers you can omit goog:chromeOptions.debuggerAddress; setting it to null or leaving it out prevents the driver from falling back to the DevTools protocol, which would disable BiDi event listener registration.