From 58db404eeff642422be29e37f81831afc0a4ef1e Mon Sep 17 00:00:00 2001 From: bukacdan Date: Tue, 17 Feb 2026 10:50:57 +0100 Subject: [PATCH 1/2] feat: support AGENT_BROWSER_CDP environment variable for --cdp flag Read AGENT_BROWSER_CDP env var as a fallback for the --cdp CLI flag, matching the pattern used by other flags (--proxy, --provider, etc.). CLI --cdp still takes precedence when both are set. Co-Authored-By: Claude Opus 4.6 --- cli/src/flags.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cli/src/flags.rs b/cli/src/flags.rs index 8214374f..0c40a6f2 100644 --- a/cli/src/flags.rs +++ b/cli/src/flags.rs @@ -238,7 +238,8 @@ pub fn parse_flags(args: &[String]) -> Flags { headers: config.headers, executable_path: env::var("AGENT_BROWSER_EXECUTABLE_PATH").ok() .or(config.executable_path), - cdp: config.cdp, + cdp: env::var("AGENT_BROWSER_CDP").ok() + .or(config.cdp), extensions, profile: env::var("AGENT_BROWSER_PROFILE").ok() .or(config.profile), From ce2f64cdf033252813b84945af50c2b84955918e Mon Sep 17 00:00:00 2001 From: bukacdan Date: Tue, 17 Feb 2026 10:51:02 +0100 Subject: [PATCH 2/2] docs: document AGENT_BROWSER_CDP environment variable Update --help output, README, SKILL.md, and docs site to mention the new AGENT_BROWSER_CDP env var alongside the --cdp flag. Co-Authored-By: Claude Opus 4.6 --- README.md | 6 +++++- cli/src/output.rs | 3 ++- docs/src/app/cdp-mode/page.mdx | 16 +++++++++++++++- skills/agent-browser/SKILL.md | 3 +++ 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4b978046..f5c259b0 100644 --- a/README.md +++ b/README.md @@ -423,7 +423,7 @@ The `-C` flag is useful for modern web apps that use custom clickable elements ( | `--json` | JSON output (for agents) | | `--full, -f` | Full page screenshot | | `--headed` | Show browser window (not headless) | -| `--cdp ` | Connect via Chrome DevTools Protocol (port or WebSocket URL) | +| `--cdp ` | Connect via Chrome DevTools Protocol (port or WebSocket URL; or `AGENT_BROWSER_CDP` env) | | `--auto-connect` | Auto-discover and connect to running Chrome (or `AGENT_BROWSER_AUTO_CONNECT` env) | | `--config ` | Use a custom config file (or `AGENT_BROWSER_CONFIG` env) | | `--debug` | Debug output | @@ -677,6 +677,10 @@ agent-browser --cdp 9222 snapshot # Connect to remote browser via WebSocket URL agent-browser --cdp "wss://your-browser-service.com/cdp?token=..." snapshot + +# Or via environment variable +export AGENT_BROWSER_CDP=9222 +agent-browser snapshot ``` The `--cdp` flag accepts either: diff --git a/cli/src/output.rs b/cli/src/output.rs index 572e2137..c970e468 100644 --- a/cli/src/output.rs +++ b/cli/src/output.rs @@ -1933,7 +1933,7 @@ Options: --json JSON output --full, -f Full page screenshot --headed Show browser window (not headless) - --cdp Connect via CDP (Chrome DevTools Protocol) + --cdp Connect via CDP (Chrome DevTools Protocol) (or AGENT_BROWSER_CDP env) --auto-connect Auto-discover and connect to running Chrome --session-name Auto-save/restore session state (cookies, localStorage) --config Use a custom config file (or AGENT_BROWSER_CONFIG env) @@ -1973,6 +1973,7 @@ Environment: AGENT_BROWSER_DEBUG Debug output AGENT_BROWSER_IGNORE_HTTPS_ERRORS Ignore HTTPS certificate errors AGENT_BROWSER_PROVIDER Browser provider (ios, browserbase, kernel, browseruse) + AGENT_BROWSER_CDP CDP connection (port or WebSocket URL) AGENT_BROWSER_AUTO_CONNECT Auto-discover and connect to running Chrome AGENT_BROWSER_ALLOW_FILE_ACCESS Allow file:// URLs to access local files AGENT_BROWSER_STREAM_PORT Enable WebSocket streaming on port (e.g., 9223) diff --git a/docs/src/app/cdp-mode/page.mdx b/docs/src/app/cdp-mode/page.mdx index 98ca5def..35bff9dd 100644 --- a/docs/src/app/cdp-mode/page.mdx +++ b/docs/src/app/cdp-mode/page.mdx @@ -34,6 +34,20 @@ The `--cdp` flag accepts either: - A port number (e.g., `9222`) for local connections via `http://localhost:{port}` - A full WebSocket URL (e.g., `wss://...` or `ws://...`) for remote browser services +You can also set the CDP endpoint via environment variable: + +```bash +# Set once, use for all commands +export AGENT_BROWSER_CDP=9222 +agent-browser snapshot + +# Works with URLs too +export AGENT_BROWSER_CDP="wss://browser-service.com/cdp?token=..." +agent-browser snapshot +``` + +The CLI `--cdp` flag takes precedence over `AGENT_BROWSER_CDP`. + ## Auto-Connect Use `--auto-connect` to automatically discover and connect to a running Chrome instance without specifying a port: @@ -86,7 +100,7 @@ This enables control of: | `--name, -n` | Locator name filter | | `--exact` | Exact text match | | `--headed` | Show browser window | -| `--cdp ` | CDP connection (port or WebSocket URL) | +| `--cdp ` | CDP connection (port or WebSocket URL, or `AGENT_BROWSER_CDP` env) | | `--auto-connect` | Auto-discover and connect to running Chrome | | `--debug` | Debug output | diff --git a/skills/agent-browser/SKILL.md b/skills/agent-browser/SKILL.md index 9ceeef89..d2fcee4d 100644 --- a/skills/agent-browser/SKILL.md +++ b/skills/agent-browser/SKILL.md @@ -171,6 +171,9 @@ agent-browser --auto-connect snapshot # Or with explicit CDP port agent-browser --cdp 9222 snapshot + +# Or via environment variable +AGENT_BROWSER_CDP=9222 agent-browser snapshot ``` ### Visual Browser (Debugging)