Communitygithub.com

cli-anything-browser

使用 DOMShell MCP 服务器的浏览器自动化命令行工具。像操作文件系统一样浏览网页。

cli-anything-browser 是什么?

cli-anything-browser 是一个基于命令行的浏览器自动化工具,它利用 DOMShell 的 MCP 服务器,将网页的可访问性树(Accessibility Tree)映射为一个类似文件系统的结构。开发者可以使用熟悉的文件系统命令(如 `ls`、`cd`、`cat`、`grep`、`click`)来导航和操作网页元素。该工具支持所有主流终端和 AI 智能体框架(如 Claude Code),并提供 JSON 输出模式以便于程序化解析。通过后台守护进程模式,它可以显著减少每次命令的冷启动开销(从 1-3 秒降至接近瞬时),非常适合需要频繁执行多条命令的自动化工作流。此外,它还包含针对 URL 限制、DOM 内容风险和私有网络访问的安全考虑,确保在 AI 智能体环境下的安全使用。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/HKUDS/CLI-Anything/tree/main/skills/cli-anything-browser

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

cli-anything-browser 是做什么的?

一个基于命令行的浏览器自动化工具,使用 DOMShell 的 MCP 服务器。可以用文件系统命令浏览网页:ls、cd、cat、grep、click。

安装

前提条件

  1. Node.js 和 npx(用于 DOMShell MCP 服务器):

    # 从 https://nodejs.org/ 安装 Node.js
    npx --version
    
  2. Chrome/Chromium 并安装 DOMShell 扩展:

    • 在 Chrome 中安装扩展
    • 使用 CLI 前确保 Chrome 正在运行
  3. Python 3.10+

安装 CLI

cd browser/agent-harness
pip install -e .

命令组

page — 页面导航

  • page open <url> — 导航到 URL
  • page reload — 重新加载当前页面
  • page back — 在历史记录中后退
  • page forward — 在历史记录中前进
  • page info — 显示当前页面信息

fs — 文件系统命令(可访问性树)

  • fs ls [path] — 列出路径下的元素
  • fs cd <path> — 更改当前目录
  • fs cat [path] — 读取元素内容
  • fs grep <pattern> [path] — 搜索文本模式
  • fs pwd — 显示当前工作目录

act — 操作命令

  • act click <path> — 点击元素
  • act type <path> <text> — 在输入框中输入文本

session — 会话管理

  • session status — 显示会话状态
  • session daemon-start — 启动持久化守护进程模式
  • session daemon-stop — 停止守护进程模式

使用示例

基本导航

# 打开页面
cli-anything-browser page open https://example.com

# 探索结构
cli-anything-browser fs ls /
cli-anything-browser fs cd /main
cli-anything-browser fs ls

# 返回根目录
cli-anything-browser fs cd /

搜索并点击

cli-anything-browser fs grep "Login"
cli-anything-browser act click /main/button[0]

填写表单

cli-anything-browser act type /main/input[0] "[email protected]"
cli-anything-browser act click /main/button[0]

JSON 输出

cli-anything-browser --json fs ls /

守护进程模式(更快的交互式使用)

# 启动持久连接
cli-anything-browser session daemon-start

# 运行命令(使用持久连接)
cli-anything-browser fs ls /
cli-anything-browser fs cd /main

# 完成时停止守护进程
cli-anything-browser session daemon-stop

交互式 REPL

cli-anything-browser

路径语法

DOMShell 使用类似文件系统的路径来表示可访问性树:

/                           — 根节点(文档)
/main                       — 主区域
/main/div[0]                — main 中的第一个 div
/main/div[0]/button[2]      — 第一个 div 中的第三个按钮
  • 数组索引为 0 起始:button[0] 表示第一个按钮
  • 使用 .. 返回上一级
  • 使用 / 表示根节点

智能体特定指南

用于解析的 JSON 输出

所有命令都支持 --json 标志,用于机器可读的输出:

cli-anything-browser --json fs ls /

返回:

{
  "path": "/",
  "entries": [
    {"name": "main", "role": "landmark", "path": "/main"}
  ]
}

错误处理

CLI 对常见问题提供清晰的错误消息:

  • 未找到 npx:从 https://nodejs.org/ 安装 Node.js
  • 未找到 DOMShell:运行 npx @apireno/domshell --version
  • MCP 调用失败:安装 DOMShell Chrome 扩展

在运行命令前检查 is_available() 的返回值。

守护进程模式提高效率

对于需要执行多条命令的智能体工作流,请使用守护进程模式:

  1. 启动守护进程:cli-anything-browser session daemon-start
  2. 运行命令:每条命令都会重用 MCP 连接
  3. 停止守护进程:cli-anything-browser session daemon-stop

这样可以避免每条命令 1-3 秒的冷启动开销。

链接

安全注意事项

重要:在使用此 CLI 与 AI 智能体时,请注意以下安全注意事项:

URL 限制

浏览器工具集在导航前会验证所有 URL:

  • 需要明确协议:URL 必须包含 http:// 或 https:// 协议(不接受无协议的 URL,如 example.com)
  • 被阻止的协议:file://、javascript://、data://、vbscript://、about://、chrome:// 以及浏览器内部协议
  • 允许的协议:仅限 http:// 和 https://(可通过 CLI_ANYTHING_BROWSER_ALLOWED_SCHEMES 配置)
  • 私有网络阻止:可选,通过 CLI_ANYTHING_BROWSER_BLOCK_PRIVATE=true 启用(默认禁用)

DOM 内容风险

可访问性树包含页面上所有可见和隐藏的元素。恶意网站可能会:

  • 使用包含操纵性文本的 ARIA 标签(例如“忽略之前指令”)
  • 使用 aria-hidden 元素注入用户不可见的内容
  • 创建混淆的 DOM 结构以误导导航

缓解措施:在与不受信任的网站交互时,请考虑:

  1. 使用 --json 标志获取结构化输出,更易于安全解析
  2. 在将 DOM 内容包含到提示中之前进行清理或过滤
  3. 将导航限制在受信任的域名

私有网络访问

默认情况下,浏览器可以访问 localhost 和私有网络(192.168.x.x、10.x.x.x 等)。要阻止:

export CLI_ANYTHING_BROWSER_BLOCK_PRIVATE=true
cli-anything-browser page open http://localhost:8080  # 将被阻止

会话隔离

多个浏览器会话共享同一个 Chrome 实例。Cookie 和身份验证状态可能会跨会话持久保存。对于敏感操作,请考虑:

  1. 使用 Chrome 的访客模式或隐身模式
  2. 在会话之间清除 Cookie
  3. 为不同的安全上下文使用单独的 Chrome 配置文件

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

cli-anything-adguardhome

>-

cli-anything-anygen

>-

cli-anything-audacity

>-

cli-anything-blender

>-

cli-anything-calibre

>-

cli-anything-ccswitch

CLI interface for CC Switch — manage AI coding tool configurations from the terminal

cli-anything-chromadb

>-

cli-anything-cloudanalyzer

Command-line interface for CloudAnalyzer — Agent-friendly harness for CloudAnalyzer, a QA platform for mapping, localization, and perception outputs. Supports 27 commands across 8 groups: point cloud evaluation, trajectory evaluation, ground segmentation QA, config-driven quality gates, baseline evolution, processing, visualization, and interactive REPL.

cli-anything-cloudcompare

Command-line interface for CloudCompare — Agent-friendly harness for CloudCompare, the open-source 3D point cloud and mesh processing software. Supports 41 commands across 9 groups: project management, session control, point cloud operations (subsample, filter, segment, analyze), mesh operations, distance computation (C2C, C2M), transformations (ICP, matrix), export (LAS/LAZ/PLY/PCD/OBJ/STL/E57), and interactive REPL.

cli-anything-comfyui

>-

cli-anything-dify-workflow

Wrapper for the Dify workflow DSL CLI. Create, inspect, validate, edit, and export Dify workflow files through a CLI-Anything harness.

cli-anything-drawio

>-

cli-anything-eez-studio

Use EEZ Studio from the command line: inspect and modify native .eez-project files, edit LVGL screens/widgets, manage SCPI commands, and invoke the real EEZ Studio backend for LVGL builds.

cli-anything-eth2-quickstart

>-

cli-anything-exa

>-

cli-anything-firefly-iii

Firefly III CLI - Personal finance management via CLI-Anything

cli-anything-freecad

Complete CLI harness for FreeCAD parametric 3D CAD modeler (258 commands). Covers ALL workbenches: Part (29 primitives + boolean + mirror + loft + sweep), Sketcher (26 cmds: geometry + constraints + editing), PartDesign (38 cmds: pad/pocket/groove/fillet/chamfer/patterns/hole/datum), Assembly (11 cmds), Mesh (16 cmds), TechDraw (15 cmds: views + dimensions + PDF/SVG), Draft (33 cmds: 2D shapes + arrays + transforms), FEM (12 cmds), CAM/CNC (10 cmds), Surface (6 cmds), Spreadsheet (7 cmds), Import (13 formats), Export (17 formats), Measure (12 cmds), Materials (21 presets). Headless FreeCAD export to STEP/IGES/STL/OBJ/DXF/PDF/glTF/3MF.

cli-anything-gimp

>-

cli-anything-godot

>-

cli-anything-inkscape

>-

相关技能