agent-browser について
agent-browser によるブラウザー自動化のスキルガイドです。スナップショットや要素参照を使った操作に加え、セッション保存、データ抽出、iOS Simulator にも対応する手順を扱います。
主な機能
- 01ページ移動と操作要素の確認
- 02要素参照による操作
- 03認証状態の保存と再利用
- 04ページテキストと JSON スナップショットの抽出
- 05複数ブラウザーセッションの実行
- 06iOS Simulator の Safari 自動化
活用シーン
- 01Web フォームの自動送信
- 02実行間でのログインセッション再利用
- 03Web ページからのコンテンツ抽出
- 04iOS Simulator でのフロー検証
インストール
コマンドをコピーしてターミナルで実行します。
npx skills add https:/ / github.com/ wshaddix/ dotnet-skills --skill agent-browserインストール後、Claude Code で/agent-browserを入力して読み込まれたか確認します。
同梱ファイル
SKILL.md と一緒にインストールされる参考資料やスクリプト。
references/authentication.mdcommands.mdproxy-support.mdsession-management.mdsnapshot-refs.mdvideo-recording.mdtemplates/authenticated-session.shcapture-workflow.shform-automation.sh詳細
agent-browser によるブラウザー自動化
基本的なワークフロー
ブラウザーの自動化はすべて、次のパターンに従います。
- 移動:
agent-browser open <url> - スナップショット:
agent-browser snapshot -i(@e1、@e2などの要素参照を取得) - 操作:参照を使ってクリック、入力、選択を行う
- 再スナップショット:ページ移動後や DOM の変更後に、新しい参照を取得します
agent-browser open https://example.com/form
agent-browser snapshot -i
# Output: @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 # Check result
必須コマンド
# Navigation
agent-browser open <url> # Navigate (aliases: goto, navigate)
agent-browser close # Close browser
# Snapshot
agent-browser snapshot -i # Interactive elements with refs (recommended)
agent-browser snapshot -i -C # Include cursor-interactive elements (divs with onclick, cursor:pointer)
agent-browser snapshot -s "#selector" # Scope to CSS selector
# Interaction (use @refs from snapshot)
agent-browser click @e1 # Click element
agent-browser fill @e2 "text" # Clear and type text
agent-browser type @e2 "text" # Type without clearing
agent-browser select @e1 "option" # Select dropdown option
agent-browser check @e1 # Check checkbox
agent-browser press Enter # Press key
agent-browser scroll down 500 # Scroll page
# Get information
agent-browser get text @e1 # Get element text
agent-browser get url # Get current URL
agent-browser get title # Get page title
# Wait
agent-browser wait @e1 # Wait for element
agent-browser wait --load networkidle # Wait for network idle
agent-browser wait --url "**/page" # Wait for URL pattern
agent-browser wait 2000 # Wait milliseconds
# Capture
agent-browser screenshot # Screenshot to temp dir
agent-browser screenshot --full # Full page screenshot
agent-browser pdf output.pdf # Save as PDF
よく使うパターン
フォームの送信
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
状態を保持した認証
# Login once and save state
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
# Reuse in future sessions
agent-browser state load auth.json
agent-browser open https://app.example.com/dashboard
セッションの保持
# Auto-save/restore cookies and localStorage across browser restarts
agent-browser --session-name myapp open https://app.example.com/login
# ... login flow ...
agent-browser close # State auto-saved to ~/.agent-browser/sessions/
# Next time, state is auto-loaded
agent-browser --session-name myapp open https://app.example.com/dashboard
# Encrypt state at rest
export AGENT_BROWSER_ENCRYPTION_KEY=$(openssl rand -hex 32)
agent-browser --session-name secure open https://app.example.com
# Manage saved states
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 # Get specific element text
agent-browser get text body > page.txt # Get all page text
# JSON output for parsing
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 への接続
# Auto-discover running Chrome with remote debugging enabled
agent-browser --auto-connect open https://example.com
agent-browser --auto-connect snapshot
# Or with explicit CDP port
agent-browser --cdp 9222 snapshot
ビジュアルブラウザー(デバッグ)
agent-browser --headed open https://example.com
agent-browser highlight @e1 # Highlight element
agent-browser record start demo.webm # Record session
ローカルファイル(PDF、HTML)
# Open local files with file:// URLs
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 シミュレーター(モバイル Safari)
# List available iOS simulators
agent-browser device list
# Launch Safari on a specific device
agent-browser -p ios --device "iPhone 16 Pro" open https://example.com
# Same workflow as desktop - snapshot, interact, re-snapshot
agent-browser -p ios snapshot -i
agent-browser -p ios tap @e1 # Tap (alias for click)
agent-browser -p ios fill @e2 "text"
agent-browser -p ios swipe up # Mobile-specific gesture
# Take screenshot
agent-browser -p ios screenshot mobile.png
# Close session (shuts down simulator)
agent-browser -p ios close
**要件:**Xcode を搭載した macOS、Appium(npm install -g appium && appium driver install xcuitest)
**実機:**事前に設定されていれば、物理的な iOS デバイスでも動作します。xcrun xctrace list devices で確認できる UDID を使って、--device "<UDID>" を指定してください。
参照のライフサイクル(重要)
参照(@e1、@e2 など)はページが変わると無効になります。次の場合は必ずスナップショットを再取得してください。
- ページ移動を伴うリンクやボタンのクリック後
- フォームの送信後
- 動的コンテンツの読み込み後(ドロップダウン、モーダルなど)
agent-browser click @e5 # Navigates to new page
agent-browser snapshot -i # MUST re-snapshot
agent-browser click @e1 # Use new refs
セマンティックロケーター(参照の代替)
参照が使用できない場合や信頼性が低い場合は、セマンティックロケーターを使用してください。
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 を実行できます。シェルのクォート処理によって複雑な式が壊れることがあります。問題を避けるには、--stdin または -b を使用してください。
# Simple expressions work with regular quoting
agent-browser eval 'document.title'
agent-browser eval 'document.querySelectorAll("img").length'
# Complex JS: use --stdin with heredoc (RECOMMENDED)
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
# Alternative: base64 encoding (avoids all shell escaping issues)
agent-browser eval -b "$(echo -n 'Array.from(document.querySelectorAll("a")).map(a => a.href)' | base64)"
**重要な理由:**シェルがコマンドを処理する際に、内部の二重引用符、! 文字(履歴展開)、バッククォート、$() によって、JavaScript が agent-browser に渡される前に壊れることがあります。--stdin と -b フラグを使えば、シェルによる解釈を完全に回避できます。
目安:
- 1 行で、入れ子の引用符がない場合 → 単一引用符を使った通常の
eval 'expression'で問題ありません - 入れ子の引用符、アロー関数、テンプレートリテラル、または複数行の場合 →
eval --stdin <<'EVALEOF'を使用してください - プログラムで生成するスクリプトの場合 → base64 と
eval -bを使用してください
詳細ドキュメント
| リファレンス | 使用する場面 |
|---|---|
| references/commands.md | すべてのオプションを含むコマンドの完全なリファレンス |
| references/snapshot-refs.md | 参照のライフサイクル、無効化ルール、トラブルシューティング |
| references/session-management.md | 並列セッション、状態の保持、並行スクレイピング |
| references/authentication.md | ログインフロー、OAuth、2FA の処理、状態の再利用 |
| references/video-recording.md | デバッグとドキュメント作成のための録画ワークフロー |
| references/proxy-support.md | プロキシ設定、地域テスト、ローテーションプロキシ |
すぐに使えるテンプレート
| テンプレート | 説明 |
|---|---|
| templates/form-automation.sh | 検証を伴うフォーム入力 |
| templates/authenticated-session.sh | 一度ログインして、状態を再利用 |
| templates/capture-workflow.sh | スクリーンショットを使ったコンテンツ抽出 |
./templates/form-automation.sh https://example.com/form
./templates/authenticated-session.sh https://app.example.com/login
./templates/capture-workflow.sh https://example.com ./output