OpenClaw 可以控制浏览器,让 Agent 像人一样浏览网页、点击按钮、填写表单。
两种模式
| 模式 | 说明 | 适用场景 |
|---|---|---|
| openclaw 托管浏览器 | OpenClaw 启动独立的 Chrome 实例 | 自动化任务、无人值守 |
| Chrome Extension | 通过扩展控制你现有的 Chrome | 需要登录态的操作 |
基础配置
{
browser: {
enabled: true,
defaultProfile: "openclaw", // openclaw=托管浏览器, chrome=扩展模式
profiles: {
openclaw: { cdpPort: 18800, color: "#FF4500" },
},
},
}
Chrome Extension 方式
适合需要使用已登录网站的场景。
安装步骤
- 在 Chrome 网上应用店搜索 OpenClaw Browser Relay 并安装
- 打开要操作的网页标签
- 点击工具栏上的 OpenClaw 图标,让 Badge 变为 ON
- 在聊天中告诉 Agent 要做什么
使用场景
- 在已登录的网站上查询信息
- 操作需要认证的后台系统
- 辅助填写表单
CDP 连接方式
如果你已有运行中的 Chrome/Chromium(开启了远程调试),可以直接连接:
{
browser: {
profiles: {
remote: {
cdpUrl: "http://10.0.0.42:9222",
color: "#00AA00",
},
},
},
}
启动 Chrome 时开启调试端口:
# macOS
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" \
--remote-debugging-port=9222 --user-data-dir=/tmp/chrome-debug
# Linux
google-chrome --remote-debugging-port=9222 --user-data-dir=/tmp/chrome-debug
CLI 操作浏览器
# 查看状态
openclaw browser --browser-profile openclaw status
# 启动浏览器
openclaw browser --browser-profile openclaw start
# 打开网页
openclaw browser --browser-profile openclaw open https://example.com
# 截图
openclaw browser --browser-profile openclaw screenshot
# 获取页面快照(AI 可读)
openclaw browser --browser-profile openclaw snapshot
Agent 能做什么
在聊天中,Agent 可以:
- 📸 截图:"帮我截个图看看这个网页"
- 🖱️ 点击:点击按钮、链接
- ⌨️ 输入:填写表单、搜索框
- 📄 阅读:读取页面内容
- 🔍 导航:跳转到指定 URL
- 📑 生成 PDF:将网页保存为 PDF
使用示例
你:帮我打开 GitHub 看看我的仓库有没有新的 Issue
Agent:好的,我来帮你查看...
[Agent 打开浏览器 → 导航到 GitHub → 读取页面 → 返回结果]
Linux 服务器上的浏览器
在无头(headless)服务器上,需要安装 Chromium:
# Ubuntu/Debian
sudo apt-get install -y chromium-browser
# 或使用 Playwright 安装
npx playwright install chromium
⚠️ Linux 常见问题:
- 缺少字体:
sudo apt-get install fonts-liberation - 沙箱问题:配置
browser.noSandbox: true - 无显示器:确保使用 headless 模式
沙箱内的浏览器
如果启用了 Docker 沙箱,可以在沙箱内运行独立的浏览器:
{
agents: {
defaults: {
sandbox: {
browser: {
enabled: true,
headless: false,
enableNoVnc: true, // 通过 noVNC 观察浏览器操作
},
},
},
},
}