Skip to content

feat: support custom headers for CDP connect#459

Open
giulio-leone wants to merge 1 commit intovercel-labs:mainfrom
giulio-leone:feat/396-cdp-headers
Open

feat: support custom headers for CDP connect#459
giulio-leone wants to merge 1 commit intovercel-labs:mainfrom
giulio-leone:feat/396-cdp-headers

Conversation

@giulio-leone
Copy link

Closes #396

Summary

Adds support for custom HTTP headers when connecting to a browser via CDP (Chrome DevTools Protocol).

Changes

  • src/browser.ts: connectViaCDP() now accepts an optional headers parameter and applies them to all browser contexts after connection via context.setExtraHTTPHeaders()
  • src/daemon.ts: Parses AGENT_BROWSER_HEADERS env var (JSON string) and passes it to the launch command
  • cli/src/connection.rs: ensure_daemon() accepts a headers parameter and forwards it as AGENT_BROWSER_HEADERS env var to the daemon process (both Unix and Windows)
  • cli/src/main.rs: Passes flags.headers to ensure_daemon()
  • cli/src/flags.rs: Initializes headers from AGENT_BROWSER_HEADERS env var as fallback (CLI --headers flag takes precedence)

Usage

# Via CLI flag
agent-browser --headers '{"Authorization": "Bearer token"}' open example.com

# Via environment variable
AGENT_BROWSER_HEADERS='{"Authorization": "Bearer token"}' agent-browser open example.com

Note on Playwright limitation

Headers are applied post-connection, not during the WebSocket handshake. Playwright's connectOverCDP() does not support connection-time headers, so we set them on the browser context immediately after the CDP connection is established using context.setExtraHTTPHeaders(). This means headers will be included in all subsequent HTTP requests made by pages in the connected browser, but not in the initial CDP WebSocket connection itself.

- Pass headers from CLI --headers flag through to daemon via AGENT_BROWSER_HEADERS env var
- Apply headers post-connection using context.setExtraHTTPHeaders() in connectViaCDP()
- Add AGENT_BROWSER_HEADERS env var fallback in flags.rs
- Parse AGENT_BROWSER_HEADERS in daemon.ts auto-launch flow

Playwright's connectOverCDP() does not support connection-time headers,
so headers are applied to browser contexts after the CDP connection is
established.
@vercel
Copy link
Contributor

vercel bot commented Feb 13, 2026

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

A member of the Team first needs to authorize it.

Copy link
Contributor

@vercel vercel bot left a comment

Choose a reason for hiding this comment

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

Additional Suggestion:

Custom headers from --headers flag are silently dropped when using --auto-connect mode because autoConnectViaCDP() doesn't receive or forward headers to connectViaCDP().

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.

Feature Request: Support custom headers for CDP connect (enables AWS AgentCore Browser integration)

1 participant