browser-auth-cdp

📁 aden232003/cdp-skill 📅 8 days ago
2
总安装量
2
周安装量
#73165
全站排名
安装命令
npx skills add https://github.com/aden232003/cdp-skill --skill browser-auth-cdp

Agent 安装分布

claude-code 2
mcpjam 1
kilo 1
junie 1
windsurf 1
zencoder 1

Skill 文档

Browser Auth via CDP

Connect agent-browser to your existing Chrome with all login sessions intact.

Quick Start

# 1. Copy Chrome profile (required - CDP needs non-default data dir)
rm -rf /tmp/chrome-debug-profile 2>/dev/null
mkdir -p /tmp/chrome-debug-profile
cp -r "$HOME/Library/Application Support/Google/Chrome/Default" /tmp/chrome-debug-profile/Default

# 2. Kill existing Chrome
killall "Google Chrome" 2>/dev/null; sleep 2

# 3. Launch Chrome with debugging
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome \
  --remote-debugging-port=9222 \
  --user-data-dir=/tmp/chrome-debug-profile \
  --no-first-run &

# 4. Wait and verify CDP is ready
sleep 5
curl -s http://127.0.0.1:9222/json/version

# 5. Connect agent-browser
agent-browser --cdp 9222 open https://x.com
agent-browser --cdp 9222 snapshot -i

Or use the helper script: scripts/launch_chrome_cdp.sh

Key Requirements

  • Must use non-default user-data-dir: Chrome requires --user-data-dir for remote debugging
  • Copy profile first: Preserves cookies/sessions from logged-in Chrome
  • Kill Chrome completely: Existing Chrome instance blocks the debug port
  • Always use --cdp 9222: All agent-browser commands need this flag when using CDP

Common Workflows

Check if logged in

agent-browser --cdp 9222 open https://x.com
agent-browser --cdp 9222 snapshot -i | grep -i "profile\|account\|logout"

Handle modals (Premium/upgrade prompts)

agent-browser --cdp 9222 snapshot -i | grep -q "Maybe later" && \
  agent-browser --cdp 9222 click @e4

X/Twitter inline reply

agent-browser --cdp 9222 open "https://x.com/user/status/123456"
sleep 2
TBOX=$(agent-browser --cdp 9222 snapshot -i | grep 'textbox "Post text"' | grep -oE 'e[0-9]+')
agent-browser --cdp 9222 fill @$TBOX "Your reply"
RBTN=$(agent-browser --cdp 9222 snapshot -i | grep 'button "Reply"' | grep -v disabled | head -1 | grep -oE 'e[0-9]+')
agent-browser --cdp 9222 click @$RBTN

Batch operations with tracking

LOG="/tmp/browser_log.txt"
echo "=== Session $(date) ===" > "$LOG"

for url in "${URLS[@]}"; do
    agent-browser --cdp 9222 open "$url"
    # ... perform actions ...
    echo "$url - DONE" >> "$LOG"
done

Troubleshooting

Issue Solution
“Failed to connect via CDP” Kill all Chrome: killall "Google Chrome", relaunch
“requires non-default data directory” Must use --user-data-dir=/tmp/chrome-debug-profile
Port 9222 not listening curl http://127.0.0.1:9222/json/version to verify
Login session missing Re-copy Chrome profile: cp -r ... /tmp/chrome-debug-profile/
Element refs changed Re-run snapshot -i after any page navigation

Platform Notes

macOS

Chrome path: /Applications/Google Chrome.app/Contents/MacOS/Google Chrome Profile path: ~/Library/Application Support/Google/Chrome/Default

Linux

Chrome path: /usr/bin/google-chrome or /opt/google/chrome/chrome Profile path: ~/.config/google-chrome/Default

Windows

Chrome path: C:\Program Files\Google\Chrome\Application\chrome.exe Profile path: %LOCALAPPDATA%\Google\Chrome\User Data\Default