Skip to content

feat(cdp): auto-connect to Windows Chrome/Edge when running in WSL#1449

Open
jorinyang wants to merge 1 commit into
vercel-labs:mainfrom
jorinyang:feat/wsl-cdp-auto-connect
Open

feat(cdp): auto-connect to Windows Chrome/Edge when running in WSL#1449
jorinyang wants to merge 1 commit into
vercel-labs:mainfrom
jorinyang:feat/wsl-cdp-auto-connect

Conversation

@jorinyang

Copy link
Copy Markdown

Summary

When agent-browser --auto-connect runs inside WSL without a display server, auto-connect currently fails because:

  • No Linux Chrome user-data dirs exist (the user's Chrome is on Windows)
  • 127.0.0.1 probes don't reach the Windows host
  • Local Chromium can't launch (no GPU/X11/Wayland)

This PR adds a WSL-aware fallback to auto_connect_cdp() in cli/src/native/cdp/chrome.rs.

What it does

When standard auto-connect methods fail and we detect WSL:

  1. Detects WSL via /proc/version ("microsoft"/"WSL") and /proc/sys/fs/binfmt_misc/WSLInterop
  2. Resolves Windows host IP from /etc/resolv.conf nameserver (set by WSL to the Windows virtual NIC)
  3. Probes common CDP ports (9222, 9223, 9224, 9229) on the Windows host — if Chrome is already running with remote debugging, connects immediately with zero launch overhead
  4. Auto-launches Windows Chrome/Edge if no CDP endpoint is found:
    • Searches known paths for chrome.exe and msedge.exe via /mnt/c/
    • Launches with --remote-debugging-port=9222 --remote-debugging-address=0.0.0.0
    • Uses isolated --user-data-dir under C:\temp — does NOT interfere with the user's normal Chrome session
    • Runs in headless mode to keep things tidy
  5. Polls for readiness with retries and returns the WebSocket URL

Files changed

File Change
cli/src/native/cdp/wsl.rs New. WSL detection, host-IP resolution, Windows browser discovery, Chrome launch, CDP probing
cli/src/native/cdp/mod.rs +1 line: pub mod wsl;
cli/src/native/cdp/chrome.rs +6 lines: WSL fallback call in auto_connect_cdp()

Total: +248 lines, 0 dependencies added.

Behavior

  • Non-WSL: zero change — is_wsl() returns false, the new code path is never entered
  • WSL with display: standard auto-connect runs first (normal behavior), WSL fallback only runs if standard methods fail
  • WSL headless: standard auto-connect fails → WSL fallback probes Windows Chrome → launches if needed → connects

Testing

Tested on WSL2 (Ubuntu 24.04) with:

  • ✅ Chrome stable — existing CDP on port 9222 detected and connected
  • ✅ Edge stable — launched fresh, connected within 2 retries
  • ✅ No browser running — Chrome auto-launched, CDP ready in ~5s
  • ✅ Non-WSL Linux — no behavioral change (is_wsl() correctly returns false)

When agent-browser runs inside WSL without a display server, the
existing auto-connect logic fails because:
- No Linux Chrome user-data dirs exist (the user's Chrome is on Windows)
- 127.0.0.1 probes don't reach the Windows host
- Local Chromium can't launch (no GPU/X11)

This adds a WSL-aware fallback to `auto_connect_cdp()` that:
1. Detects WSL via /proc/version and /proc/sys/fs/binfmt_misc/WSLInterop
2. Resolves the Windows host IP from /etc/resolv.conf
3. Probes common CDP ports (9222-9224, 9229) on the Windows host
4. If no running Chrome is found, auto-launches Windows Chrome/Edge
   with --remote-debugging-port and --remote-debugging-address=0.0.0.0
5. Polls for CDP readiness and returns the WebSocket URL

The launch uses a separate --user-data-dir under C:\temp to avoid
conflicts with the user's normal browser session.

Tested on WSL2 with both Chrome stable and Edge.
@vercel

vercel Bot commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Someone is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

Comment thread cli/src/native/cdp/wsl.rs

let mut cmd = Command::new(exe_path);
cmd.arg(format!("--remote-debugging-port={}", port))
.arg("--remote-debugging-address=0.0.0.0") // allow connections from WSL

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WSL CDP launcher binds the unauthenticated Chrome DevTools Protocol endpoint to 0.0.0.0, exposing full browser control to the entire physical LAN rather than only the WSL-facing interface.

Fix on Vercel

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