agent-browser について
AIエージェント向けのヘッドレスブラウザー自動化CLIです。アクセシビリティツリーの要素参照で対象を指定でき、分離セッション、JSON出力、CDP接続にも対応します。
主な機能
- 01ブラウザーの移動と操作
- 02要素参照付きアクセシビリティスナップショット
- 03並列実行用の分離セッション
- 04機械可読なJSON出力
- 05既存ブラウザーへのCDP接続
- 06スクリーンショットとPDFの生成
活用シーン
- 01フォーム入力とWebサイトの移動
- 02アクセシブルなページ内容の取得
- 03Webアプリケーションの自動テスト
- 04ブラウザータスクの並列実行
インストール
コマンドをコピーしてターミナルで実行します。
npx skills add https:/ / github.com/ ckorhonen/ claude-skills --skill agent-browserインストール後、Claude Code で/agent-browserを入力して読み込まれたか確認します。
詳細
agent-browser CLI
AI エージェント向けに設計されたヘッドレスブラウザー自動化 CLI です。Rust ベースの高速な実行と、LLM の推論に最適化された要素参照を備えています。
概要
agent-browser は、AI エージェントのワークフローに特化した CLI を通じて、プログラムからブラウザーを制御できます。アクセシビリティツリーから決定的な要素参照(@e1、@e2 など)を使用するため、一貫した要素の指定が重要な LLM ベースの自動化に最適です。
主な機能:
- Node.js フォールバックを備えた高速な Rust ベースの CLI
- 安定した LLM の推論に使える要素参照(
@e1、@e2) - 並列ブラウザーインスタンス向けのセッション分離
- プログラムから解析できる JSON 出力
- 要素の検出に使えるアクセシビリティツリーのスナップショット
- 既存のブラウザーインスタンス向け CDP 接続のサポート
使用する場面
- Web 操作の自動化(フォーム入力、クリック、ナビゲーション)
- アクセシビリティツリーの解析による Web コンテンツのスクレイピング
- Web アプリケーションのプログラムによるテスト
- 分離されたブラウザーセッションが必要なマルチエージェントのシナリオ
- スクリーンショットの撮影と PDF の生成
- Web ページの状態変化の監視
前提条件
- Node.js >= 18 または Bun ランタイム
- Chromium(
agent-browser installでインストール)
インストール
# Install globally
bun install -g agent-browser
# Download Chromium
agent-browser install
# Linux with system dependencies
agent-browser install --with-deps
インストールを確認します:
agent-browser --version
クイックスタート
# Navigate to a page
agent-browser open https://example.com
# Get accessibility snapshot with element refs
agent-browser snapshot -i # -i = interactive elements only
# Click an element by ref
agent-browser click @e2
# Fill a form field
agent-browser fill @e3 "[email protected]"
# Take a screenshot
agent-browser screenshot output.png
基本的なワークフロー
1. ページを開いてスナップショットを取得する
# Open URL
agent-browser open https://example.com
# Get interactive elements with refs
agent-browser snapshot -i --json
スナップショットには次のような要素が返されます:
@e1 link "Home"
@e2 textbox "Email"
@e3 button "Submit"
2. 参照を使って操作する
# Click by ref
agent-browser click @e2
# Type into focused element
agent-browser type @e2 "[email protected]"
# Fill (clears first, then types)
agent-browser fill @e2 "[email protected]"
# Press keyboard key
agent-browser press Enter
3. 状態を確認する
# Check element visibility
agent-browser is visible @e3
# Get element text
agent-browser get text @e1
# Get page URL
agent-browser get url
コマンドリファレンス
ナビゲーション
| コマンド | 説明 |
|---|---|
open <url> | URL に移動します |
back | 履歴を戻ります |
forward | 履歴を進みます |
reload | 現在のページを再読み込みします |
close | ブラウザーを閉じます |
操作
| コマンド | 説明 |
|---|---|
click <ref> | 要素をクリックします |
dblclick <ref> | 要素をダブルクリックします |
type <ref> <text> | 要素にテキストを入力します |
fill <ref> <text> | 要素をクリアして入力します |
press <key> | キーボードキーを押します(Enter、Tab、Control+a) |
hover <ref> | 要素にカーソルを合わせます |
focus <ref> | 要素にフォーカスします |
check <ref> | チェックボックスをオンにします |
uncheck <ref> | チェックボックスをオフにします |
select <ref> <val> | ドロップダウンの選択肢を選びます |
scroll <dir> [px] | スクロールします(up/down/left/right) |
wait <ref|ms> | 要素または指定したミリ秒数だけ待機します |
情報
| コマンド | 説明 |
|---|---|
snapshot | 参照を含むアクセシビリティツリーを取得します |
snapshot -i | インタラクティブ要素のみを取得します |
snapshot -c | コンパクト表示にします(空の要素を削除) |
snapshot -d <n> | ツリーの深さを制限します |
get text <ref> | 要素のテキストコンテンツを取得します |
get html <ref> | 要素の HTML を取得します |
get value <ref> | 入力値を取得します |
get url | 現在のページの URL を取得します |
get title | ページタイトルを取得します |
screenshot [path] | スクリーンショットを撮影します |
screenshot --full | ページ全体のスクリーンショットを撮影します |
pdf <path> | ページを PDF として保存します |
状態の確認
| コマンド | 説明 |
|---|---|
is visible <ref> | 要素が表示されているか確認します |
is enabled <ref> | 要素が有効か確認します |
is checked <ref> | チェックボックスがオンか確認します |
要素の検索
# Find by role and click
agent-browser find role button click --name Submit
# Find by text
agent-browser find text "Sign In" click
# Find by label
agent-browser find label "Email" fill "[email protected]"
# Find by placeholder
agent-browser find placeholder "Search..." type "query"
セッション管理
セッションを使うと、並列実行向けにブラウザーインスタンスを分離できます:
# Use named session
agent-browser --session login-flow open https://app.com
# Different session for another task
agent-browser --session checkout open https://app.com/cart
# List active sessions
agent-browser session list
# Environment variable (persistent across commands)
export AGENT_BROWSER_SESSION=my-session
agent-browser open https://example.com
JSON 出力
機械可読な出力には --json を使用します:
# Snapshot as JSON
agent-browser snapshot -i --json
# Get element info as JSON
agent-browser get text @e1 --json
# Parse in scripts
agent-browser get url --json | jq -r '.url'
よくある問題
このセクションでは、よくある失敗とデバッグ方法を説明します。それぞれの問題について、表示される症状、根本原因、解決方法を示します。
ブラウザーが見つからない
症状: Error: Browser executable not found at default path または agent-browser: command not found
原因: Chromium がインストールされていないか、agent-browser CLI が PATH にありません。
解決方法:
# Install Chromium
agent-browser install
# For Linux, install system dependencies
agent-browser install --with-deps
# Verify installation
agent-browser --version
ページ変更後に要素の参照が古くなる
症状: 直前に使ったにもかかわらず Error: Element @e2 not found が表示される、またはクリックが無反応になる
原因: DOM が更新されると(ナビゲーション、ページの再読み込み、動的コンテンツなど)、要素の参照が変わります。参照が有効なのは、現在の DOM スナップショットに対してのみです。
対処方法:
# Always re-snapshot after major page changes
agent-browser click @e1 # Click submit
agent-browser wait 2000 # Wait for navigation
agent-browser snapshot -i --json # Get fresh refs
agent-browser click @e1 # Use new ref (was @e1 before? Verify!)
予防策: スクリプトでは、ナビゲーションや動的な読み込みのたびに新しい参照を取得してください。
セッションの競合とポートのバインド
症状: Error: Session "default" already in use または Port 9222 already in use が表示される
原因: 前回のコマンドやクラッシュしたスクリプトによるブラウザーセッションがまだ実行中で、新しいセッションを開始できません。
対処方法:
# List active sessions
agent-browser session list
# Kill a specific session
agent-browser session kill my-session
# Use unique session names to avoid conflicts
agent-browser --session upload-$(date +%s) open https://app.com
# Or set environment variable once
export AGENT_BROWSER_SESSION=task-$(date +%s)
agent-browser open https://example.com
agent-browser close
非表示の要素でクリックや操作が機能しない
症状: agent-browser click @e5 が成功するものの何も起きない、またはスクリーンショットで要素が見えない
原因: 要素がビューポートの外にある、CSS(display: none、visibility: hidden)で非表示になっている、または別の要素に覆われています。アクセシビリティツリーに表示されていても、ブラウザーから操作できない場合があります。
対処方法:
# Check visibility before interaction
agent-browser is visible @e5
# Scroll to make element visible
agent-browser scroll down 500
# Take screenshot to visually verify
agent-browser screenshot current-state.png
# Try parent element if child is deeply nested
agent-browser click @e4 # Click parent button instead
予防策: 重要な操作の前後には必ずスクリーンショットを撮り、画面の状態を確認してください。
ナビゲーションまたは要素の待機がタイムアウトする
症状: Error: Timeout waiting for element が表示される、またはリンクをクリックした後にスクリプトが無期限に停止する
原因:
- 要素が存在しない、または想定より長く待たないと表示されない
- ナビゲーションが停止している(ネットワークエラー、ページが読み込まれない)
- 要素セレクターが誤っている
対処方法:
# Explicit wait before checking for element
agent-browser wait 2000 # Wait 2 seconds
agent-browser snapshot -i --json # Check if element exists
# Wait for specific element to appear
agent-browser wait @e3
# Increase timeout with explicit waits in script
agent-browser click @submit
sleep 3 # Shell script sleep
agent-browser snapshot -i
# Check page title to verify navigation worked
agent-browser get title
予防策: ナビゲーションが発生するフォーム送信やリンクのクリックの後に、明示的な wait コマンドを追加してください。
スナップショットが空、または想定した要素がない
症状: agent-browser snapshot -i --json が [] またはごく少数の要素を返す一方で、スクリーンショットでは要素が見える
原因:
- JavaScript(React、Vue など)でページコンテンツが描画され、まだ完了していない
- 要素にアクセシブルなラベルやロールが設定されていない
-iフラグによる絞り込みが厳しすぎる
対処方法:
# Wait for content to render
agent-browser wait 2000
agent-browser snapshot -i
# Remove interactive-only filter to see all elements
agent-browser snapshot -c # Compact but includes all elements
# Increase tree depth to find nested elements
agent-browser snapshot -d 5
# Use full snapshot to diagnose
agent-browser snapshot --json | jq . | less
# Check page title to verify page loaded
agent-browser get title
予防策: JavaScript の描画負荷が高いページを開いた後に、待機時間を追加してください。
フォームへの入力が機能しない、またはテキストが途中で切れる
症状: テキストが途中で切れているように見える、最初の数文字しか入力されない、またはフィールドが空のままになる
原因:
- 入力前にフィールドへフォーカスしていなかった(競合状態)
- フィールドに入力検証または文字数制限がある
- JavaScript のイベントハンドラーが、特定の入力速度や blur イベントを想定している
対処方法:
# Always focus explicitly before filling
agent-browser focus @e2
agent-browser wait 500 # Let field settle
agent-browser fill @e2 "[email protected]"
# For fields with slow JS event handling
agent-browser type @e2 "first part"
agent-browser wait 500
agent-browser type @e2 "second part"
# Verify what was actually entered
agent-browser get value @e2
予防策: フォームに入力したらすぐに get value で値が正しく入力されたことを確認してください。
ネットワークリクエストの失敗、または外部 API のタイムアウト
症状: ページは読み込まれるもののデータが表示されない、または実際の API にアクセスすると統合テストが失敗する
原因:
- 外部 API の応答が遅い、または到達できない
- CORS エラー(ブラウザーが別ドメインへのリクエストをブロックする)
- 認証ヘッダーがない
- ネットワークが分離されている(テスト環境)
対処方法:
# Set custom headers for auth
agent-browser --headers '{"Authorization": "Bearer token123"}' open https://api.example.com
# Mock API responses instead
agent-browser network route "**/api/data" --body '{"result":"mocked"}'
# Add explicit wait for API response
agent-browser wait 3000 # Give API time to respond
agent-browser snapshot -i
# Fallback: Use `--headed` to see error messages
agent-browser --headed open https://app.com
agent-browser click @e1 # See browser console errors
予防策: テストでは network route を使って外部 API をモックしてください。本番環境では、自動化を実行する前に接続を確認してください。
ブラウザーがクラッシュする、または応答しなくなる
症状: agent-browser コマンドが停止する、プロセスがセグメンテーション違反でクラッシュする、または Chrome のウィンドウが予期せず閉じる
原因:
- メモリー不足(長時間実行するセッションやスクリーンショットが多すぎる)
- CDP 接続が無効
- まれに発生する Chromium/Playwright のクラッシュ
- システムリソースが不足している
対処方法:
# Restart with fresh session
agent-browser session kill all-sessions # Or specify a name
# Use lightweight mode with limited resources
agent-browser --session lite open https://minimal-site.com
# Reduce screenshot frequency
# Instead of: agent-browser screenshot after every click
# Do: agent-browser screenshot only on failure
# Check system resources
top -n 1 | head -20
# Run with --debug for crash diagnostics
agent-browser --debug open https://example.com 2>&1 | tail -50
予防策:
- セッションを明示的に終了します:
agent-browser close - 長時間実行するタスクには一意のセッション名を使います
- 長時間の自動化スクリプトではメモリーを監視します
要素の参照が曖昧(複数の要素に @e1 が表示される)
症状: 複数の要素が同じ @e 番号に解決され、@e1 をクリックすると誤った要素が操作される
原因: アクセシビリティツリーが類似した要素(ボタン、リンク)をまとめ、agent-browser が一意性ではなく順序に基づいて参照を割り当てます。
対処方法:
# Use full snapshot to understand structure
agent-browser snapshot -d 3 --json > structure.json
cat structure.json | jq . # Examine hierarchy
# Click using find by text if available
agent-browser find text "Specific Button Text" click
# Use CSS selector if accessibility tree isn't clear
agent-browser find selector "button.submit-btn" click
# Take screenshot and count visually
agent-browser screenshot debug.png
# Then manually map which @eN corresponds to which button
# Use context to disambiguate
agent-browser get text @e1 # Check what @e1 actually is
予防策: 重要な操作の前に、要素のテキストを確認するかスクリーンショットを撮り、対象が正しいことを必ず確認してください。
高度な機能
CDP 接続
既存の Chrome インスタンスに接続します。
# Start Chrome with debugging
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222
# Connect agent-browser
agent-browser --cdp 9222 snapshot
動画の録画
# Start recording
agent-browser record start recording.webm https://example.com
# Perform actions...
agent-browser click @e1
agent-browser fill @e2 "test"
# Stop and save
agent-browser record stop
ネットワークのインターセプト
# Block requests to URL pattern
agent-browser network route "**/analytics/*" --abort
# Mock API response
agent-browser network route "**/api/user" --body '{"name": "Test"}'
# View captured requests
agent-browser network requests
カスタムヘッダー
# Set auth headers
agent-browser --headers '{"Authorization": "Bearer token123"}' open https://api.example.com
ブラウザー拡張機能
# Load extension
agent-browser --extension /path/to/extension open https://example.com
AI エージェントのパターン
フォームの自動化
#!/bin/bash
# Login automation script
agent-browser open https://app.com/login
# Get form elements
agent-browser snapshot -i --json > elements.json
# Fill credentials
agent-browser fill @e2 "[email protected]"
agent-browser fill @e3 "password123"
# Submit
agent-browser click @e4
# Wait for navigation
agent-browser wait 2000
# Verify login
agent-browser get url --json | jq -r '.url'
データの抽出
#!/bin/bash
# Scrape product data
agent-browser open https://shop.com/products
# Get page content
agent-browser snapshot --json > snapshot.json
# Extract specific element text
agent-browser get text '[data-testid="price"]' --json
# Screenshot for verification
agent-browser screenshot products.png
複数ページのワークフロー
#!/bin/bash
SESSION="checkout-flow"
# Step 1: Add to cart
agent-browser --session $SESSION open https://shop.com/product/123
agent-browser --session $SESSION click @add-to-cart-button
agent-browser --session $SESSION wait 1000
# Step 2: Go to checkout
agent-browser --session $SESSION open https://shop.com/checkout
agent-browser --session $SESSION snapshot -i
# Step 3: Fill shipping
agent-browser --session $SESSION fill @shipping-name "John Doe"
agent-browser --session $SESSION fill @shipping-address "123 Main St"
# Cleanup
agent-browser --session $SESSION close
オプションのリファレンス
| オプション | 説明 |
|---|---|
--session <name> | 分離されたブラウザーセッション |
--json | JSON 出力形式 |
--headed | ブラウザーウィンドウを表示(ヘッドレスではない) |
--cdp <port> | Chrome DevTools Protocol 経由で接続 |
--headers <json> | リクエスト用の HTTP ヘッダー |
--proxy <url> | プロキシサーバー |
--executable-path <path> | カスタムブラウザー実行ファイル |
--extension <path> | ブラウザー拡張機能を読み込む |
--full, -f | ページ全体のスクリーンショット |
--debug | デバッグ出力 |
環境変数
| 変数 | 説明 |
|---|---|
AGENT_BROWSER_SESSION | デフォルトのセッション名 |
AGENT_BROWSER_EXECUTABLE_PATH | カスタムブラウザーパス |
AGENT_BROWSER_STREAM_PORT | WebSocket ストリーミングポート |
例
例 1:簡単な Web スクレイピング
ユーザーのリクエスト:
"Scrape the product title and price from https://example.com/product/123"
ワークフロー:
# 1. Navigate to page
agent-browser open https://example.com/product/123
# 2. Get accessibility snapshot
agent-browser snapshot -i --json > page.json
# 3. Identify elements (example output):
# @e5 heading "Premium Widget Pro"
# @e12 text "$49.99"
# 4. Extract data
agent-browser get text @e5 --json # Returns: {"text": "Premium Widget Pro"}
agent-browser get text @e12 --json # Returns: {"text": "$49.99"}
期待される出力:
{
"title": "Premium Widget Pro",
"price": "$49.99"
}
所要時間: 2~3 秒
例 2:検証を伴うフォーム送信
ユーザーのリクエスト:
"Fill out the contact form at https://example.com/contact and verify submission"
ワークフロー:
# 1. Navigate and snapshot
agent-browser open https://example.com/contact
agent-browser snapshot -i
# Example snapshot output:
# @e1 textbox "Name"
# @e2 textbox "Email"
# @e3 textbox "Message"
# @e4 button "Send"
# 2. Fill form fields
agent-browser fill @e1 "John Doe"
agent-browser fill @e2 "[email protected]"
agent-browser fill @e3 "I have a question about your product"
# 3. Submit
agent-browser click @e4
# 4. Wait for response
agent-browser wait 2000
# 5. Verify success
agent-browser snapshot -i | grep "Thank you"
# Or take screenshot for manual verification
agent-browser screenshot success.png
期待される結果:
- フォームが正常に送信される
- ページに確認メッセージが表示される
- 成功状態を示すスクリーンショットが保存される
所要時間: 4~6 秒
例 3:セッションを使った複数ページのワークフロー
ユーザーのリクエスト:
"Add item to cart, proceed to checkout, and fill shipping info"
ワークフロー:
# Use session for state persistence across commands
SESSION="checkout-flow-$(date +%s)"
# 1. Add to cart
agent-browser --session $SESSION open https://shop.example.com/product/widget
agent-browser --session $SESSION snapshot -i | grep "Add to Cart"
agent-browser --session $SESSION click @add-to-cart # Assuming @add-to-cart ref found
agent-browser --session $SESSION wait 1000 # Wait for cart update
# 2. Go to checkout
agent-browser --session $SESSION open https://shop.example.com/checkout
agent-browser --session $SESSION snapshot -i
# 3. Fill shipping form (refs from snapshot)
agent-browser --session $SESSION fill @shipping-name "Jane Smith"
agent-browser --session $SESSION fill @shipping-address "456 Oak Ave"
agent-browser --session $SESSION fill @shipping-city "Portland"
agent-browser --session $SESSION select @shipping-state "OR"
agent-browser --session $SESSION fill @shipping-zip "97201"
# 4. Take screenshot before submission
agent-browser --session $SESSION screenshot checkout-filled.png
# 5. Cleanup
agent-browser --session $SESSION close
期待される結果:
- 商品が正常にカートに追加される
- チェックアウトフォームに配送先の詳細が入力される
- 入力済みのフォームを示すスクリーンショットが保存される
- セッションがクリーンアップされる
所要時間: 8~12 秒
例 4:ログインとデータ抽出
ユーザーのリクエスト:
"Log into dashboard, navigate to reports, and extract table data"
ワークフロー:
SESSION="dashboard-scrape"
# 1. Login
agent-browser --session $SESSION open https://app.example.com/login
agent-browser --session $SESSION snapshot -i
# Fill login form
agent-browser --session $SESSION fill @email "[email protected]"
agent-browser --session $SESSION fill @password "secretpass"
agent-browser --session $SESSION click @submit
agent-browser --session $SESSION wait 2000
# 2. Navigate to reports
agent-browser --session $SESSION open https://app.example.com/reports
agent-browser --session $SESSION wait 1000
# 3. Extract table data
agent-browser --session $SESSION snapshot --json > reports.json
# Parse JSON to extract table rows
# @e20 table
# @e21 row "Q1 2024, $50,000, 15% growth"
# @e22 row "Q2 2024, $62,000, 24% growth"
agent-browser --session $SESSION get text @e20 --json
# 4. Cleanup
agent-browser --session $SESSION close
期待される出力:
{
"reports": [
{"quarter": "Q1 2024", "revenue": "$50,000", "growth": "15%"},
{"quarter": "Q2 2024", "revenue": "$62,000", "growth": "24%"}
]
}
所要時間: 6~10 秒
トラブルシューティング
問題:要素の参照が見つからない
症状:
Error: Element @e5 not found
原因: ページの更新後に要素の参照が変わったか、スナップショットが古くなっています
解決策:
# 1. Get fresh snapshot
agent-browser snapshot -i
# 2. Verify element ref in output
# Look for expected element in snapshot output
# 3. If element doesn't appear, try without -i flag
agent-browser snapshot # Shows all elements, not just interactive
# 4. If still missing, check if page loaded completely
agent-browser wait 2000 # Wait for page to settle
agent-browser snapshot -i
問題:ナビゲーションの待機がタイムアウトする
症状:
Error: Navigation timeout after 30000ms
原因: ページの読み込みに時間がかかるか、ネットワークに問題があります
解決策:
# 1. Check if page is accessible
agent-browser --headed open https://example.com # Visual debugging
# 2. Increase wait time after navigation
agent-browser open https://slow-site.com
agent-browser wait 5000 # Wait 5 seconds
# 3. Check network requests
agent-browser network requests # See what's loading
# 4. Use CDP connection for better control
agent-browser --cdp 9222 open https://example.com
問題:クリックが機能しない
症状: 要素のクリックコマンドは実行されますが、何も起こりません
原因: 要素が表示されていない、無効になっている、または別の要素に覆われています
解決策:
# 1. Check if element is visible
agent-browser is visible @e3
# Returns: true/false
# 2. Check if element is enabled
agent-browser is enabled @e3
# 3. Try scrolling to element first
agent-browser scroll down 500
agent-browser wait 500
agent-browser click @e3
# 4. Take screenshot to see page state
agent-browser screenshot debug.png
# 5. Try double-click instead
agent-browser dblclick @e3
問題:フォーム入力が反映されない
症状: テキストを入力してもフォームフィールドが空のままです
原因: JavaScript フレームワークが特別なイベントまたは遅延を必要としています
解決策:
# 1. Focus element first
agent-browser focus @e2
agent-browser wait 200
# 2. Use fill instead of type (clears first)
agent-browser fill @e2 "text content"
# 3. Add delays between keystrokes
agent-browser type @e2 "slow"
agent-browser wait 100
# 4. Try pressing Tab after filling to trigger validation
agent-browser fill @e2 "[email protected]"
agent-browser press Tab
問題:セッションの保持に関する問題
症状: 前回のセッション状態を利用できません
原因: セッション名が適切に設定されていないか、ブラウザーが予期せず終了しました
解決策:
# 1. Always use explicit session names
SESSION="my-workflow-$(date +%s)" # Unique session ID
agent-browser --session $SESSION open https://example.com
# 2. Check active sessions
agent-browser --session $SESSION get url
# If error, session doesn't exist
# 3. Don't reuse session names across runs
# Each workflow should have unique session ID
# 4. Cleanup sessions when done
agent-browser --session $SESSION close
問題:Chromium のインストールに失敗する
症状:
Error: Failed to download Chromium
原因: ネットワークの問題、ディスク容量不足、またはシステム依存関係の不足です
解決策:
# 1. Check disk space
df -h # Ensure >2GB free
# 2. Retry installation with verbose output
agent-browser install --debug
# 3. On Linux, install system dependencies first
agent-browser install --with-deps
# 4. Use custom browser if needed
agent-browser --executable-path /usr/bin/chromium open https://example.com
# 5. Verify installation
agent-browser --version
ls ~/.cache/ms-playwright/ # Check if Chromium exists
問題:JSON 出力の形式が不正
症状: コマンドの JSON 出力を解析できません
原因: テキストと JSON の出力が混在しているか、JSON モードでエラーが発生しています
解決策:
# 1. Use --json flag consistently
agent-browser get text @e5 --json # Not: agent-browser get text @e5
# 2. Redirect stderr to separate stream
agent-browser snapshot --json 2>errors.log >output.json
# 3. Validate JSON output
agent-browser snapshot --json | jq . # Will error if invalid
# 4. Check for error messages in output
agent-browser snapshot --json | grep -E '^{' | jq .
ベストプラクティス
- 必ず最初にスナップショットを取得する:操作の前に要素の参照を取得します
- 解析には
--jsonを使う:スクリプトで処理できる形式で出力します - セッションを分離する:並行ワークフローには
--sessionを使います - 明示的に待機する:ナビゲーションやクリックの後に
waitコマンドを追加します - インタラクティブスナップショットを使う:ノイズを減らすには
-iフラグを使います - 状態を検証する:クリックする前に要素が表示されていることを確認します
- 失敗時にスクリーンショットを撮る:自動化が失敗したときに状態を記録します