agent-browser-local
npx skills add https://github.com/nwparker/agent-browser-local --skill agent-browser-local
Agent 安装分布
Skill 文档
Local Browser Automation with agent-browser + Comet CDP
This skill connects agent-browser to the user’s real local Comet browser via Chrome DevTools Protocol (CDP). This gives you access to the user’s actual browser profile â cookies, login sessions, extensions, and all.
Setup: Launch Browser with CDP
Before any browser commands, you must ensure Comet is running with CDP enabled. Do this ONCE per session, then reuse for all subsequent commands.
Headed Mode (default â visible browser window)
# Kill any existing Comet to avoid "Opening in existing session" conflicts
pkill -9 -f Comet 2>/dev/null; sleep 2
# Launch with CDP
/Applications/Comet.app/Contents/MacOS/Comet --remote-debugging-port=${COMET_CDP_PORT:-9222} &disown 2>/dev/null
sleep 3
# Verify CDP is ready
curl -s http://localhost:${COMET_CDP_PORT:-9222}/json/version >/dev/null && echo "CDP ready"
# Bring window to foreground
osascript -e 'tell application "Comet" to activate'
Headless Mode (no visible window, still uses real profile)
pkill -9 -f Comet 2>/dev/null; sleep 2
/Applications/Comet.app/Contents/MacOS/Comet --headless=new --remote-debugging-port=${COMET_CDP_PORT:-9222} &disown 2>/dev/null
sleep 3
curl -s http://localhost:${COMET_CDP_PORT:-9222}/json/version >/dev/null && echo "CDP ready"
Check if Already Running
Before launching, check if Comet CDP is already available from a previous command in this session:
curl -s http://localhost:${COMET_CDP_PORT:-9222}/json/version >/dev/null 2>&1 && echo "ALREADY RUNNING" || echo "NEED TO LAUNCH"
If already running, skip the launch step entirely. This is critical for session reuse.
Core Rule: Always Pass --cdp
Every agent-browser command MUST include --cdp ${COMET_CDP_PORT:-9222}. This connects to the local Comet instance instead of launching a new browser.
# CORRECT â uses local Comet
agent-browser --cdp ${COMET_CDP_PORT:-9222} open https://example.com
agent-browser --cdp ${COMET_CDP_PORT:-9222} snapshot -i
agent-browser --cdp ${COMET_CDP_PORT:-9222} click @e1
# WRONG â would launch isolated headless browser, losing auth
agent-browser open https://example.com
Workflow
Every interaction follows this pattern:
- Ensure CDP is running (check first, launch only if needed)
- Navigate:
agent-browser --cdp 9222 open <url> - Snapshot:
agent-browser --cdp 9222 snapshot -i(get element refs like@e1,@e2) - Interact: Use refs to click, fill, select â always with
--cdp 9222 - Re-snapshot: After navigation or DOM changes, get fresh refs
# Check CDP
curl -s http://localhost:9222/json/version >/dev/null 2>&1 || { echo "Launch Comet first"; exit 1; }
# Navigate and interact
agent-browser --cdp 9222 open https://example.com/dashboard
agent-browser --cdp 9222 snapshot -i
# Output: @e1 [button] "Settings", @e2 [link] "Profile", ...
agent-browser --cdp 9222 click @e2
agent-browser --cdp 9222 snapshot -i # Fresh refs after navigation
Command Chaining
Commands can be chained with &&. Always include --cdp on each:
agent-browser --cdp 9222 open https://example.com && agent-browser --cdp 9222 wait --load networkidle && agent-browser --cdp 9222 snapshot -i
Essential Commands
All standard agent-browser commands work â just prepend --cdp 9222:
# Navigation
agent-browser --cdp 9222 open <url>
agent-browser --cdp 9222 close # Disconnects agent-browser (does NOT close Comet)
# Snapshot & Interaction
agent-browser --cdp 9222 snapshot -i
agent-browser --cdp 9222 click @e1
agent-browser --cdp 9222 fill @e2 "text"
agent-browser --cdp 9222 select @e3 "option"
agent-browser --cdp 9222 press Enter
agent-browser --cdp 9222 scroll down 500
# Information
agent-browser --cdp 9222 get text @e1
agent-browser --cdp 9222 get url
agent-browser --cdp 9222 get title
# Wait
agent-browser --cdp 9222 wait @e1
agent-browser --cdp 9222 wait --load networkidle
# Capture
agent-browser --cdp 9222 screenshot
agent-browser --cdp 9222 screenshot --full
agent-browser --cdp 9222 screenshot --annotate
User Preferences
Ask the user on first invocation:
- Headed or headless? Default to headed so the user can see what’s happening.
- If the user says “headed”, bring Comet to the foreground with
osascript -e 'tell application "Comet" to activate'after launch.
Session Lifecycle
- Launch once: The browser persists for the entire Claude Code session
- Reuse always: Check CDP before every interaction, never re-launch if already running
- Don’t kill on “close”:
agent-browser --cdp 9222 closeonly disconnects agent-browser’s Playwright session from the CDP endpoint. It does NOT close or kill Comet. The user’s browser stays open. - No cleanup needed: When the Claude Code session ends, Comet keeps running as the user’s normal browser
Configuration
| Variable | Default | Description |
|---|---|---|
COMET_CDP_PORT |
9222 |
CDP port for remote debugging |
Troubleshooting
“Opening in existing browser session”
Comet was already running without CDP. Kill it first, then relaunch with --remote-debugging-port:
pkill -9 -f Comet 2>/dev/null; sleep 2
/Applications/Comet.app/Contents/MacOS/Comet --remote-debugging-port=9222 &disown
CDP not responding
Wait longer â some systems need 3-5 seconds for Comet to start:
for i in {1..10}; do curl -s http://localhost:9222/json/version >/dev/null 2>&1 && break; sleep 1; done
Port already in use
Another process is using port 9222. Either kill it or use a different port:
COMET_CDP_PORT=9333 agent-browser --cdp 9333 open https://example.com