Community程式設計與開發github.com

Jamie-BitFlight/claude_skills

Anthropic Claude Code、Codex、Cursor 等工具的瀏覽器自動化外掛

claude_skills 是什麼?

這項技能提供了一個強大的瀏覽器自動化工具組,專為 Anthropic Claude Code、Codex 和 Cursor 等 AI 編碼代理所設計。它讓代理能透過簡單的指令來導航網頁、填寫表單、點擊元素與擷取資料。核心工作流程包含導航、快照、互動與重新快照四個步驟,確保代理能正確處理動態內容。技能支援指令鏈結、多會話管理、認證狀態持久化、視覺差異比對,以及 iOS 模擬器測試。透過 `agent-browser` CLI,代理可執行從基本表單提交到複雜資料擷取與驗證的各種自動化任務。

相容平台✓Claude Code✓Codex CLI✓Cursor
npx skills add Jamie-BitFlight/claude_skills

Installed? Explore more 程式設計與開發 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

使用 agent-browser 進行瀏覽器自動化

核心工作流程

每個瀏覽器自動化都遵循以下模式:

  1. 導航:agent-browser open <url>
  2. 快照:agent-browser snapshot -i(取得元素參考,如 @e1、@e2)
  3. 互動:使用參考進行點擊、填寫、選擇
  4. 重新快照:在導航或 DOM 變更後,取得最新參考
agent-browser open https://example.com/form
agent-browser snapshot -i
# 輸出:@e1 [input type="email"], @e2 [input type="password"], @e3 [button] "Submit"

agent-browser fill @e1 "[email protected]"
agent-browser fill @e2 "password123"
agent-browser click @e3
agent-browser wait --load networkidle
agent-browser snapshot -i  # 檢查結果

指令鏈結

指令可以使用 && 在單一 shell 呼叫中鏈結。瀏覽器會透過背景守護行程在不同指令之間保持狀態,因此鏈結既安全又比個別呼叫更有效率。

# 在單一呼叫中鏈結開啟 + 等待 + 快照
agent-browser open https://example.com && agent-browser wait --load networkidle && agent-browser snapshot -i

# 鏈結多個互動
agent-browser fill @e1 "[email protected]" && agent-browser fill @e2 "password123" && agent-browser click @e3

# 導航並擷取
agent-browser open https://example.com && agent-browser wait --load networkidle && agent-browser screenshot page.png

何時鏈結: 當你不需要在繼續之前讀取中間指令的輸出時(例如,開啟 + 等待 + 螢幕截圖),使用 &&。當你需要先解析輸出時(例如,快照以發現參考,然後使用這些參考進行互動),則分別執行指令。

必要指令

# 導航
agent-browser open <url>              # 導覽(別名:goto, navigate)
agent-browser close                   # 關閉瀏覽器

# 快照
agent-browser snapshot -i             # 帶有參考的互動元素(建議使用)
agent-browser snapshot -i -C          # 包含游標互動元素(具有 onclick、cursor:pointer 的 div)
agent-browser snapshot -s "#selector" # 限定 CSS 選擇器範圍

# 互動(使用快照中的 @ref)
agent-browser click @e1               # 點擊元素
agent-browser click @e1 --new-tab     # 點擊並在新分頁中開啟
agent-browser fill @e2 "text"         # 清除並輸入文字
agent-browser type @e2 "text"         # 輸入文字而不清除
agent-browser select @e1 "option"     # 選擇下拉選項
agent-browser check @e1               # 勾選核取方塊
agent-browser press Enter             # 按下按鍵
agent-browser scroll down 500         # 捲動頁面

# 取得資訊
agent-browser get text @e1            # 取得元素文字
agent-browser get url                 # 取得目前 URL
agent-browser get title               # 取得頁面標題

# 等待
agent-browser wait @e1                # 等待元素
agent-browser wait --load networkidle # 等待網路閒置
agent-browser wait --url "**/page"    # 等待 URL 模式
agent-browser wait 2000               # 等待毫秒

# 擷取
agent-browser screenshot              # 螢幕截圖至暫存目錄
agent-browser screenshot --full       # 全頁螢幕截圖
agent-browser screenshot --annotate   # 附有編號元素標籤的註解螢幕截圖
agent-browser pdf output.pdf          # 另存為 PDF

# 差異比對(比較頁面狀態)
agent-browser diff snapshot                          # 比較目前與上次快照
agent-browser diff snapshot --baseline before.txt    # 比較目前與已儲存檔案
agent-browser diff screenshot --baseline before.png  # 視覺像素差異
agent-browser diff url <url1> <url2>                 # 比較兩個頁面
agent-browser diff url <url1> <url2> --wait-until networkidle  # 自訂等待策略
agent-browser diff url <url1> <url2> --selector "#main"  # 限定元素範圍

常見模式

表單提交

agent-browser open https://example.com/signup
agent-browser snapshot -i
agent-browser fill @e1 "Jane Doe"
agent-browser fill @e2 "[email protected]"
agent-browser select @e3 "California"
agent-browser check @e4
agent-browser click @e5
agent-browser wait --load networkidle

含有狀態持久化的認證

# 登入一次並儲存狀態
agent-browser open https://app.example.com/login
agent-browser snapshot -i
agent-browser fill @e1 "$USERNAME"
agent-browser fill @e2 "$PASSWORD"
agent-browser click @e3
agent-browser wait --url "**/dashboard"
agent-browser state save auth.json

# 在未來的工作階段中重複使用
agent-browser state load auth.json
agent-browser open https://app.example.com/dashboard

工作階段持久化

# 在瀏覽器重新啟動時自動儲存/還原 cookie 和 localStorage
agent-browser --session-name myapp open https://app.example.com/login
# ... 登入流程 ...
agent-browser close  # 狀態自動儲存至 ~/.agent-browser/sessions/

# 下一次,狀態會自動載入
agent-browser --session-name myapp open https://app.example.com/dashboard

# 加密靜態狀態
agent-browser state list
agent-browser state show myapp-default.json
agent-browser state clear myapp
agent-browser state clean --older-than 7

資料擷取

agent-browser open https://example.com/products
agent-browser snapshot -i
agent-browser get text @e5           # 取得特定元素文字
agent-browser get text body > page.txt  # 取得所有頁面文字

# 用於解析的 JSON 輸出
agent-browser snapshot -i --json
agent-browser get text @e1 --json

平行工作階段

agent-browser --session site1 open https://site-a.com
agent-browser --session site2 open https://site-b.com

agent-browser --session site1 snapshot -i
agent-browser --session site2 snapshot -i

agent-browser session list

連線至現有 Chrome

# 自動探索已啟用遠端除錯的執行中 Chrome
agent-browser --auto-connect open https://example.com
agent-browser --auto-connect snapshot

# 或使用明確的 CDP 埠
agent-browser --cdp 9222 snapshot

視覺化瀏覽器(除錯)

agent-browser --headed open https://example.com
agent-browser highlight @e1          # 突顯元素
agent-browser record start demo.webm # 錄製工作階段
agent-browser profiler start         # 開始 Chrome DevTools 效能分析
agent-browser profiler stop trace.json # 停止並儲存分析檔案(路徑為選填)

本機檔案(PDF、HTML)

# 使用 file:// URL 開啟本機檔案
agent-browser --allow-file-access open file:///path/to/document.pdf
agent-browser --allow-file-access open file:///path/to/page.html
agent-browser screenshot output.png

iOS 模擬器(Mobile Safari)

# 列出可用的 iOS 模擬器
agent-browser device list

# 在特定裝置上啟動 Safari
agent-browser -p ios --device "iPhone 16 Pro" open https://example.com

# 與桌面端相同的工作流程 - 快照、互動、重新快照
agent-browser -p ios snapshot -i
agent-browser -p ios tap @e1          # 輕觸(點擊的別名)
agent-browser -p ios fill @e2 "text"
agent-browser -p ios swipe up         # 行動裝置專用手勢

# 拍攝螢幕截圖
agent-browser -p ios screenshot mobile.png

# 關閉工作階段(關閉模擬器)
agent-browser -p ios close

需求: macOS 與 Xcode、Appium(npm install -g appium && appium driver install xcuitest)

實體裝置: 如果預先設定好,可與實體 iOS 裝置搭配使用。使用 --device "<UDID>",其中 UDID 來自 xcrun xctrace list devices。

差異比對(驗證變更)

在執行動作後使用 diff snapshot 來驗證它是否產生了預期的效果。這會將會話中的目前無障礙功能樹與上次快照進行比較。

# 典型工作流程:快照 -> 動作 -> 差異比對
agent-browser snapshot -i          # 取得基準快照
agent-browser click @e2            # 執行動作
agent-browser diff snapshot        # 查看變更內容(自動與上次快照比較)

用於視覺回歸測試或監控:

# 儲存基準螢幕截圖,然後稍後比較
agent-browser screenshot baseline.png
# ... 經過一段時間或進行變更 ...
agent-browser diff screenshot --baseline baseline.png

# 比較暫存環境與正式環境
agent-browser diff url https://staging.example.com https://prod.example.com --screenshot

diff snapshot 輸出使用 + 表示新增,- 表示移除,類似於 git diff。diff screenshot 會產生一張差異圖,其中變更的像素會以紅色標示,並顯示不匹配百分比。

逾時與慢速頁面

本機瀏覽器的預設 Playwright 逾時時間為 60 秒。對於慢速網站或大型頁面,請使用明確的等待指令,而不是依賴預設逾時:

# 等待網路活動穩定(最適合慢速頁面)
agent-browser wait --load networkidle

# 等待特定元素出現
agent-browser wait "#content"
agent-browser wait @e1

# 等待特定 URL 模式(在重新導向後很有用)
agent-browser wait --url "**/dashboard"

# 等待 JavaScript 條件
agent-browser wait --fn "document.readyState === 'complete'"

# 最後手段:等待固定時間(毫秒)
agent-browser wait 5000

在處理持續慢速的網站時,請在 open 之後使用 wait --load networkidle 以確保頁面在拍攝快照前已完全載入。如果特定元素渲染速度較慢,請直接使用 wait <selector> 或 wait @ref 等待它。

工作階段管理與清理

當同時執行多個代理或自動化任務時,請務必使用命名工作階段以避免衝突:

# 每個代理都有自己獨立的工作階段
agent-browser --session agent1 open site-a.com
agent-browser --session agent2 open site-b.com

# 檢查作用中的工作階段
agent-browser session list

完成後請務必關閉瀏覽器工作階段,以避免洩漏處理程序:

agent-browser close                    # 關閉預設工作階段
agent-browser --session agent1 close   # 關閉特定工作階段

如果之前的工作階段未正常關閉,守護行程可能仍在執行。請在開始新工作前使用 agent-browser close 進行清理。

參考生命週期(重要)

當頁面變更時,參考(@e1、@e2 等)會失效。請務必在以下情況後重新執行快照:

  • 點擊會導覽的連結或按鈕
  • 表單提交
  • 動態內容載入(下拉式選單、彈出視窗)
agent-browser click @e5              # 導航至新頁面
agent-browser snapshot -i            # 必須重新快照
agent-browser click @e1              # 使用新的參考

註解螢幕截圖(視覺模式)

使用 --annotate 拍攝帶有疊加在互動元素上的編號標籤的螢幕截圖。每個標籤 [N] 對應於參考 @eN。這也會快取參考,因此你可以立即與元素互動,而無需單獨執行快照。

agent-browser screenshot --annotate
# 輸出包含圖片路徑和圖例:
#   [1] @e1 button "Submit"
#   [2] @e2 link "Home"
#   [3] @e3 textbox "Email"
agent-browser click @e2              # 使用註解螢幕截圖中的參考進行點擊

在以下情況使用註解螢幕截圖:

  • 頁面有未標籤的圖示按鈕或僅限視覺的元素
  • 你需要驗證視覺佈局或樣式
  • 存在 Canvas 或圖表元素(對文字快照不可見)
  • 你需要關於元素位置的空間推理

語意定位器(參考的替代方案)

當參考不可用或不可靠時,請使用語意定位器:

agent-browser find text "Sign In" click
agent-browser find label "Email" fill "[email protected]"
agent-browser find role button click --name "Submit"
agent-browser find placeholder "Search" type "query"
agent-browser find testid "submit-btn" click

JavaScript 評估(eval)

使用 eval 在瀏覽器環境中執行 JavaScript。Shell 引用可能會損壞複雜運算式 -- 請使用 --stdin 或 -b 以避免問題。

# 簡單運算式可以使用一般引用
agent-browser eval 'document.title'
agent-browser eval 'document.querySelectorAll("img").length'

# 複雜 JS:使用 --stdin 搭配 heredoc(建議使用)
agent-browser eval --stdin <<'EVALEOF'
JSON.stringify(
  Array.from(document.querySelectorAll("img"))
    .filter(i => !i.alt)
    .map(i => ({ src: i.src.split("/").pop(), width: i.width }))
)
EVALEOF

# 替代方案:base64 編碼(避免所有 shell 跳脫問題)
agent-browser eval -b "$(echo -n 'Array.from(document.querySelectorAll("a")).map(a => a.href)' | base64)"

為什麼這很重要: 當 shell 處理你的指令時,內層的雙引號、! 字元(歷史擴展)、反引號和 $() 都可能在你將 JavaScript 傳遞給 agent-browser 之前就將其損壞。--stdin 和 -b 旗標會完全繞過 shell 的解讀。

經驗法則:

  • 單行、無巢狀引號 -> 使用單引號的常規 eval 'expression' 即可
  • 巢狀引號、箭頭函式、範本字面值或多行 -> 使用 eval --stdin <<'EVALEOF'
  • 程式化/生成的腳本 -> 使用 eval -b 搭配 base64

設定檔

在專案根目錄建立 agent-browser.json 以設定持久性設定:

{
  "headed": true,
  "proxy": "http://localhost:8080",
  "profile": "./browser-data"
}

優先級(從低到高):~/.agent-browser/config.json < ./agent-browser.json < 環境變數 < CLI 旗標。使用 --config <path> 或 AGENT_BROWSER_CONFIG 環境變數來指定自訂設定檔(如果遺失或無效,則會出現錯誤並結束)。所有 CLI 選項對應於 camelCase 鍵(例如,--executable-path -> "executablePath")。布林旗標接受 true/false 值(例如,--headed false 會覆蓋設定)。來自使用者與專案的設定擴展會合併,而非取代。

深入文件

參考資料使用時機
references/commands.md包含所有選項的完整指令參考

Individual skills in this repo

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

Jamie-BitFlight/agentskill-kaizen-meta-docs

Agentskill kaizen plugin documentation index. Load when needing to read about cross-platform notes, improvement plans, or DuckDB integration.

Jamie-BitFlight/bash-51-features

Bash 5.1 release features and improvements with practical examples. Use when working with Bash 5.1 features, epoch time variables, redirection enhancements, or when user asks about Bash 5.1 changes, new features, or version-specific capabilities.

Jamie-BitFlight/bash-52-features

Bash 5.2 release features and improvements with practical examples. Use when working with Bash 5.2 features, variable handling enhancements, readline improvements, or when user asks about Bash 5.2 changes, new features, or version-specific capabilities.

Jamie-BitFlight/bash-53-features

Bash 5.3 release features and improvements with practical examples. Use when working with Bash 5.3 features, new command substitution, GLOBSORT, loadable builtins, or when user asks about Bash 5.3 changes, new features, or version-specific capabilities.

Jamie-BitFlight/bash-development

This skill should be used when the user asks to "write a bash script", "create a shell script", "implement bash function", "parse arguments in bash", "handle errors in bash", or mentions bash development, shell scripting, script templates, or modern bash patterns.

Jamie-BitFlight/bash-lint

This skill should be used when the user asks to "lint bash script", "run shellcheck", "format shell script", "use shfmt", "fix shellcheck errors", or mentions shell script linting, formatting, code quality, or pre-commit hooks for bash.

Jamie-BitFlight/bash-logging

This skill should be used when the user asks to "add logging to bash script", "colorize output", "implement log levels", "CI/CD sections", "terminal colors in bash", or mentions logging functions, emoji output, collapsible CI sections, or shlocksmith.

Jamie-BitFlight/bash-portability

This skill should be used when the user asks about "POSIX compatibility", "portable shell scripts", "cross-shell compatibility", "bashisms", "shebang selection", or mentions writing scripts that work on different shells (bash, sh, dash, zsh) or different systems.

Jamie-BitFlight/bash-testing

This skill should be used when the user asks to "test bash script", "write shell tests", "use shunit2", "use shellspec", "create test suite for bash", or mentions unit testing, test frameworks, mocking, or test-driven development for shell scripts.

Jamie-BitFlight/brainstorming-skill

You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or when users request help with ideation, marketing, and strategic planning. Explores user intent, requirements, and design before implementation using research-validated prompt patterns.

Jamie-BitFlight/clang-format

Configure clang-format code formatting. Use when: user mentions clang-format or .clang-format, analyzing code style/patterns, creating/modifying formatting config, troubleshooting formatting, brace styles/indentation/spacing/alignment/pointer alignment, or codifying conventions.

Jamie-BitFlight/commitlint

When setting up commit message validation for a project. When project has commitlint.config.js or .commitlintrc files. When configuring CI/CD to enforce commit format. When extracting commit rules for LLM prompt generation. When debugging commit message rejection errors.

Jamie-BitFlight/conventional-commits

When writing a git commit message. When task completes and changes need committing. When project uses semantic-release, commitizen, git-cliff. When choosing between feat/fix/chore/docs types. When indicating breaking changes. When generating changelogs from commit history.

Jamie-BitFlight/dasel-reference

Use when querying, modifying, or converting JSON, YAML, TOML, XML, CSV, HCL, or INI with dasel v3. Complete reference for selectors, functions, conditionals, variables, spread operator, type casting, and format-specific patterns.

Jamie-BitFlight/data-exploration

Use when exploring unknown structured data files with dasel v3 — discover schema, list keys, find nested values, sample arrays, identify data types across JSON, YAML, TOML, XML, CSV, HCL, INI formats

Jamie-BitFlight/data-transformation

Use when modifying, converting, or transforming structured data with dasel v3 — in-place mutations, format conversion, batch operations, array manipulation, object construction, and merge patterns across JSON, YAML, TOML, XML, CSV, HCL, INI

Jamie-BitFlight/delegate

Decompose substantive work into phases, dispatch each phase to a sub-agent, and adjudicate what comes back. Use whenever a request asks for implementation, investigation, a fix, a review, or any change to files — including small ones — and whenever you are about to read source or run a diagnostic yourself instead of handing it off. Also use when a report from a sub-agent needs judging, when a phase needs re-dispatching, or when a user names one instance of a pattern. Does not apply when your own prompt begins "Your ROLE_TYPE is sub-agent." — then follow references/sub-agent-contract.md instead.

Jamie-BitFlight/enterprise-hibernate-hbm

Dasel v3 query patterns for Hibernate .hbm.xml mapping files — entity-table binding, Java property-to-column extraction, one-to-many set/list/bag relationship tracing, many-to-one foreign key discovery, batch scanning across 60+ HBM files. Use when querying Hibernate ORM class mappings, extracting schema metadata from Java persistence layer, or auditing entity-column relationships in enterprise legacy codebases.

Jamie-BitFlight/enterprise-installanywhere

Dasel v3 query patterns for InstallAnywhere .iap_xml installer definitions — use when querying action sequences, discovering variables, resolving platform conditions, navigating panels, or comparing installer variants. Files are 2.5+ MB, 65,000+ lines — too large for context reads, requires structural dasel queries.

Jamie-BitFlight/enterprise-maven-pom

Dasel v3 selector patterns for Maven POM XML files — use when querying dependency versions, filtering by groupId or scope, extracting module hierarchy from parent POMs, or detecting version conflicts across enterprise multi-module Java projects. Load this skill when working with pom.xml files using dasel.

相關技能