Skip to content

Enable BiDi support for connect-existing mode#50

Open
MayCXC wants to merge 1 commit intomozilla:mainfrom
MayCXC:connect-existing-bidi-v2
Open

Enable BiDi support for connect-existing mode#50
MayCXC wants to merge 1 commit intomozilla:mainfrom
MayCXC:connect-existing-bidi-v2

Conversation

@MayCXC
Copy link
Copy Markdown

@MayCXC MayCXC commented Mar 28, 2026

Supersedes #45 (rebased on current main).

Summary

--connect-existing mode currently disables all BiDi-dependent features (console events, network events) because selenium-webdriver's createSession() hangs when trying to auto-upgrade to BiDi with an existing Firefox instance.

This PR enables BiDi by:

  1. Requesting webSocketUrl: true in the session capabilities sent to geckodriver
  2. Reading the webSocketUrl from the session response (set by Firefox's Remote Agent)
  3. Implementing getBidi() on GeckodriverHttpDriver that opens a WebSocket to that URL, satisfying the IBiDi interface already defined upstream

The existing hasBidi check ('getBidi' in driver) naturally picks up the new method, so console and network event collection work without further changes.

Behavior

  • Launch mode: No change. Continues to use selenium-webdriver with enableBidi().
  • Connect-existing with --remote-debugging-port: BiDi features (console, network) now work.
  • Connect-existing without --remote-debugging-port: getBidi() throws a clear error. All non-BiDi features continue to work as before.

Changes

  • src/firefox/core.ts: 45 insertions, 6 deletions (all in GeckodriverHttpDriver)

Test plan

  • tsc --noEmit passes
  • bun run build succeeds
  • Manual: --connect-existing with Firefox started with --marionette --remote-debugging-port 9222, verified list_console_messages and list_network_requests return data

GeckodriverHttpDriver now requests webSocketUrl: true in the session
capabilities and exposes a getBidi() method that opens a WebSocket to
Firefox's Remote Agent. This allows BiDi-dependent features (console
events, network events) to work when using --connect-existing.

The WebSocket is opened lazily on the first getBidi() call and closed
on quit/kill. The IBiDi interface already defined upstream is satisfied
by wrapping the ws WebSocket instance.

No behavior change for launch mode (continues to use selenium-webdriver
with enableBidi). No behavior change for connect-existing when Firefox
was not started with --remote-debugging-port (getBidi throws a clear
error, same as before but with a better message).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant