Communitygithub.com

cli-anything-browser

使用 DOMShell MCP 伺服器進行瀏覽器自動化的命令列工具。將 Chrome 對應為檔案系統。

cli-anything-browser 是什麼?

cli-anything-browser 是一款命令列工具,專為瀏覽器自動化設計,其核心是 DOMShell MCP 伺服器。它將網頁的無障礙樹(Accessibility Tree)以檔案系統路徑的方式呈現,讓使用者能像操作檔案系統一樣(使用 `ls`、`cd`、`cat`、`grep`、`click` 等指令)來導航和操作網頁。此工具特別適合 AI 代理的開發與使用,支援 JSON 輸出格式以便程式解析,並提供持久化連線(Daemon 模式)來減少重複啟動的延遲。它支援在 Python 環境中安裝,並需要 Chrome 瀏覽器及其 DOMShell 擴充功能配合。此外,工具內建了安全機制,例如限制 URL 協議、可選的私有網路封鎖,並針對 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:// 協議(不接受像 example.com 這樣不含協議的 URL)
  • 封鎖的協議: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

>-

相關技能