Overview
This skill summarizes the experience of using agent-browser for browser automation in the Kimi CLI environment, especially for common issues and solutions.
Core Workflow
Basic Usage Patterns
# 1. 打开网页
npx agent-browser open <url>
# 2. 等待页面加载
npx agent-browser wait --load networkidle
# 3. 获取页面快照(带交互元素引用)
npx agent-browser snapshot -i
4. Interactive operations (using references like @e1, @e2)
npx agent-browser fill @e1 "text" npx agent-browser click @e2
5. Screenshotnpx agent-browser screenshot output.png --full
### 命令链式执行
使用 `&&` 连接多个命令提高效率:
```bash
npx agent-browser open https://example.com && \
npx agent-browser wait --load networkidle && \
npx agent-browser snapshot -i
Common Issues and Solutions
Issue 1: First-time installation timeout
Symptom:
npx agent-browser open https://example.com
# Error: Command killed by timeout
Cause:npx On first run, it needs to download and install the agent-browser package and its 184+ dependencies.
Solution:
- Install manually to a local directory:
npm install agent-browser - Or use a longer timeout
- After installation, subsequent uses will be faster
Issue 2: Playwright browser download failure
Symptom:
npx playwright install chromium
# Error: Proxy connection ended before receiving CONNECT response
Cause:agent-browser is based on Playwright and by default needs to download the Chromium browser, but may encounter network/proxy issues.
Solution: Use the system-installed Chrome
# 检查系统 Chrome
which google-chrome # 或 chromium, chromium-browser
# 使用系统 Chrome 运行
npx agent-browser --executable-path /usr/bin/google-chrome open <url>
Important: If the daemon is already running, it needs to be closed first:
npx agent-browser close
sleep 1
npx agent-browser --executable-path /usr/bin/google-chrome open <url>
Issue 3: Session conflict
Symptom:--executable-path ignored: daemon already running
Solution: Close the existing session and restart:
npx agent-browser close
npx agent-browser --executable-path /usr/bin/google-chrome open <url>
Utility Script
Use scripts/check-browser-env.sh to quickly check the environment:
# 检查系统浏览器并输出建议命令
./scripts/check-browser-env.sh
Example output:
找到系统浏览器: /usr/bin/google-chrome
建议命令:
npx agent-browser --executable-path /usr/bin/google-chrome open <url>
Complete example: search and take a screenshot
# 安装依赖(首次)
cd /tmp && npm install agent-browser
# 使用系统 Chrome 执行
npx agent-browser --executable-path /usr/bin/google-chrome open https://www.baidu.com
npx agent-browser wait --load networkidle
npx agent-browser snapshot -i
# 填写搜索框并搜索(假设 @e13 是搜索框,@e14 是按钮)
npx agent-browser fill @e13 "OpenAI"
npx agent-browser click @e14
npx agent-browser wait --load networkidle
# 截图
npx agent-browser screenshot /tmp/search_result.png --full
Quick Reference
| Command | Purpose |
|---|---|
open <url> |
Open a webpage |
close |
Close the browser |
snapshot -i |
Get a snapshot of interactive elements |
fill @eN "text" |
Fill in an input field |
click @eN |
Click an element |
wait --load networkidle |
Wait for the network to be idle |
screenshot <path> --full |
Full-page screenshot |
Environment Checklist
Before starting browser automation, check:
-
agent-browserwhether it is installed (npm list agent-browser) - System Chrome/Chromium path (
which google-chrome) - whether there is a leftover daemon (
npx agent-browser closecleanup) - whether the network connection is normal