Skip to content

Add --marionette-host for remote/tunneled Firefox#51

Draft
MayCXC wants to merge 2 commits intomozilla:mainfrom
MayCXC:marionette-host
Draft

Add --marionette-host for remote/tunneled Firefox#51
MayCXC wants to merge 2 commits intomozilla:mainfrom
MayCXC:marionette-host

Conversation

@MayCXC
Copy link
Copy Markdown

@MayCXC MayCXC commented Mar 28, 2026

Depends on #50.

Summary

Adds a --marionette-host CLI parameter (and MARIONETTE_HOST env var) for connecting to Firefox through an SSH tunnel or on a remote host.

When connecting to a tunneled Firefox (e.g., ssh -L 2828:127.0.0.1:2828 remote-host), the Marionette and BiDi ports are reachable on a different hostname than 127.0.0.1. This parameter controls:

  • Which host geckodriver connects to for Marionette (--marionette-host passed to geckodriver)
  • Where the BiDi WebSocket URL is rewritten to point (replacing 127.0.0.1 in the webSocketUrl capability)

Example

# SSH tunnel forwarding Firefox ports from a remote host
ssh -L 2828:127.0.0.1:2828 -L 9222:127.0.0.1:9222 remote-host

# MCP server connects through the tunnel
npx firefox-devtools-mcp --connect-existing --marionette-host host.internal

Changes

  • src/cli.ts: Add --marionette-host option
  • src/firefox/types.ts: Add marionetteHost to FirefoxLaunchOptions
  • src/firefox/core.ts: Pass host to geckodriver, rewrite BiDi WebSocket URL
  • src/index.ts: Plumb marionetteHost through to options

Note on Firefox Host header validation

Firefox's httpd.js rejects WebSocket connections with a Host header that doesn't match a configured server identity. When connecting via a tunnel hostname (e.g., host.internal), Firefox needs to be configured to accept that host. AFAICT for remote devtools, this needs a Firefox bug report to make --remote-allow-hosts also configure httpd.js identities.

@MayCXC MayCXC force-pushed the marionette-host branch 9 times, most recently from c5f78ac to 7ecf7d0 Compare March 29, 2026 08:05
MayCXC added 2 commits March 29, 2026 08:51
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).
Adds a --marionette-host CLI parameter (and MARIONETTE_HOST env var)
that controls which host geckodriver connects to for Marionette and
where the BiDi WebSocket connection is directed.

When connecting to a remote or tunneled Firefox (e.g., via SSH port
forwarding), the Marionette and BiDi ports are on a different host
than localhost. This parameter lets geckodriver reach the tunnel
endpoint while preserving the original Host header for Firefox's
WebSocket allowHosts check.
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