运行时依赖
版本
命令
安装命令
点击复制技能文档
浏览器自动化与 agent-browser 安装 npm 推荐:npm install -g agent-browser agent-browser 安装:agent-browser install agent-browser 安装 --with-deps 从源码安装:git clone https://github.com/vercel-labs/agent-browser cd agent-browser pnpm install pnpm build agent-browser 安装 快速开始: agent-browser open # 导航到页面 agent-browser snapshot -i # 获取带有引用(refs)的交互元素 agent-browser click @e1 # 点击元素 agent-browser fill @e2 "text" # 填充输入元素 agent-browser close # 关闭浏览器 核心工作流程: 导航:agent-browser open 快照:agent-browser snapshot -i (返回带有引用(refs)的元素,如 @e1、@e2) 使用快照中的引用进行交互 在导航或显著的 DOM 更改后重新快照 命令: 导航: agent-browser open # 导航到 URL agent-browser back # 后退 agent-browser forward # 前进 agent-browser reload # 刷新页面 agent-browser close # 关闭浏览器 快照(页面分析): agent-browser snapshot # 完整的可访问性树 agent-browser snapshot -i # 仅交互元素(推荐) agent-browser snapshot -c # 紧凑输出 agent-browser snapshot -d 3 # 限制深度到 3 agent-browser snapshot -s "#main" # 限制到 CSS 选择器 交互(使用快照中的引用): agent-browser click @e1 # 点击 agent-browser dblclick @e1 # 双击 agent-browser focus @e1 # 聚焦元素 agent-browser fill @e2 "text" # 清除并输入 agent-browser type @e2 "text" # 输入(不清除) agent-browser press Enter # 按键 agent-browser press Control+a # 按键组合 agent-browser keydown Shift # 按键按下 agent-browser keyup Shift # 按键释放 agent-browser hover @e1 # 悬停 agent-browser check @e1 # 选中复选框 agent-browser uncheck @e1 # 取消选中复选框 agent-browser select @e1 "value" # 选择下拉菜单 agent-browser scroll down 500 # 滚动页面 agent-browser scrollintoview @e1 # 滚动元素到视图 agent-browser drag @e1 @e2 # 拖拽 agent-browser upload @e1 file.pdf # 上传文件 获取信息: agent-browser get text @e1 # 获取元素文本 agent-browser get html @e1 # 获取元素 innerHTML agent-browser get value @e1 # 获取输入值 agent-browser get attr @e1 href # 获取属性 agent-browser get title # 获取页面标题 agent-browser get url # 获取当前 URL agent-browser get count ".item" # 计数匹配元素 agent-browser get box @e1 # 获取边界框 检查状态: agent-browser is visible @e1 # 检查是否可见 agent-browser is enabled @e1 # 检查是否启用 agent-browser is checked @e1 # 检查是否选中 截图和 PDF: agent-browser screenshot # 截图到标准输出 agent-browser screenshot path.png # 保存到文件 agent-browser screenshot --full # 全页截图 agent-browser pdf output.pdf # 保存为 PDF 视频录制: agent-browser record start ./demo.webm # 开始录制(使用当前 URL + 状态) agent-browser click @e1 # 执行操作 agent-browser record stop # 停止并保存视频 agent-browser record restart ./take2.webm # 停止当前 + 开始新录制 录制创建一个新环境,但保留会话中的 cookie 和存储。 如果没有提供 URL,它将自动返回到当前页面。 对于平滑的演示,请先探索,然后开始录制。 等待: agent-browser wait @e1 # 等待元素 agent-browser wait 2000 # 等待毫秒 agent-browser wait --text "Success" # 等待文本 agent-browser wait --url "/dashboard" # 等待 URL 模式 agent-browser wait --load networkidle # 等待网络空闲 agent-browser wait --fn "window.ready" # 等待 JS 条件 鼠标控制: agent-browser mouse move 100 200 # 移动鼠标 agent-browser mouse down left # 按下鼠标按钮 agent-browser mouse up left # 释放鼠标按钮 agent-browser mouse wheel 100 # 滚动鼠标轮 语义定位器(替代引用): agent-browser find role button click --name "Submit" agent-browser find text "Sign In" click agent-browser find label "Email" fill "user@test.com" agent-browser find first ".item" click agent-browser find nth 2 "a" text 浏览器设置: agent-browser set viewport 1920 1080 # 设置视口大小 agent-browser set device "iPhone 14" # 模拟设备 agent-browser set geo 37.7749 -122.4194 # 设置地理位置 agent-browser set offline on # 切换离线模式 agent-browser set headers '{"X-Key":"v"}' # 额外的 HTTP 头 agent-browser set credentials user pass # HTTP 基本认证 agent-browser set media dark # 模拟颜色方案 Cookie 和存储: agent-browser cookies # 获取所有 cookie