browser
browserbase/skills
透過命令列介面(CLI)命令,使用自然語言自動化網頁瀏覽器互動。支援本地和遠端 Browserbase 會話,具備驗證碼解決、住宅代理和會話持久化功能。
...展開全部瀏覽器自動化
使用 Claude 透過 browse CLI 自動化瀏覽器互動。
環境檢查
在執行任何瀏覽器命令之前,請驗證 CLI 是否可用:
which browse || npm install -g browse
環境選擇(本地與遠端)
CLI 支援每個命令顯式的環境標誌。如果您不進行任何操作,當設定了 BROWSERBASE_API_KEY 時,下一個會話預設使用 Browserbase,否則使用本地環境。
本地模式
browse open <url> --local</url>啟動一個乾淨的隔離本地瀏覽器browse open <url> --auto-connect</url>附加到已執行的可除錯 Chrome;當沒有可除錯的 Chrome 時使用--localbrowse open <url> --cdp <port></port></url>附加到特定的 CDP 目標- 最佳適用場景:開發、本地主機、受信任的網站以及可復現的執行環境
遠端模式(Browserbase)
browse open <url> --remote</url>啟動 Browserbase 會話- 如果沒有本地標誌,當設定了
BROWSERBASE_API_KEY時,Browserbase 也是預設選項 - 提供:Browserbase 身份、經過驗證的瀏覽器、自動驗證碼解決、住宅代理、會話持久化
- 當以下情況時使用遠端模式: 目標網站有機器人檢測、驗證碼、IP 速率限制、Cloudflare 保護或需要特定地理位置的訪問
- 在 https://browserbase.com/settings 獲取憑據
何時選擇哪種模式
- 可重複的本地測試 / 乾淨狀態:
browse open <url> --local</url> - 複用本地登入/Cookie:
browse open <url> --auto-connect</url> - 簡單瀏覽(文件、維基、公共 API):本地模式即可
- 受保護的網站(登入牆、驗證碼、反爬取):使用遠端模式
- 如果本地模式因機器人檢測或訪問被拒而失敗:切換到遠端模式
命令
守護程序啟動後,大多數驅動程式命令在本地、遠端和 CDP 會話中均有效。
導航
browse open <url> # 前往 URL
browse open <url> --local # 在乾淨的本地瀏覽器中前往 URL
browse open <url> --remote # 在 Browserbase 會話中前往 URL
browse reload # 重新載入當前頁面
browse back # 在歷史記錄中後退
browse forward # 在歷史記錄中前進
</url></url></url>頁面狀態(優先使用快照而非截圖)
browse snapshot # 獲取帶有元素引用的可訪問性樹(快速、結構化)
browse screenshot --path <path> # 擷取視覺截圖(較慢,使用視覺令牌)
browse get url # 獲取當前 URL
browse get title # 獲取頁面標題
browse get text # 獲取文字內容(使用 "body" 獲取所有文字)
browse get html # 獲取元素的 HTML 內容
browse get value # 獲取表單欄位值
</path>將 browse snapshot 作為了解頁面狀態的預設方式——它返回帶有元素引用的可訪問性樹,您可以使用這些引用來進行互動。僅在需要視覺上下文(佈局、影象、除錯)時使用 browse screenshot。
互動
browse click <ref> # 透過快照中的引用點選元素(例如,@0-5)
browse type <text> # 在聚焦的元素中輸入文字
browse fill <value> # 填充輸入框;如果需要按回車鍵,請新增 --press-enter
browse select <values...> # 選擇下拉選項
browse press <key> # 按鍵(Enter、Tab、Escape、Cmd+A 等)
browse mouse drag <fromx><fromy><tox><toy> # 從一點拖動到另一點
browse mouse scroll <x><y><deltax><deltay> # 在座標處滾動
browse highlight # 高亮顯示頁面上的元素
browse is visible # 檢查元素是否可見
browse is checked # 檢查元素是否被選中
browse wait <type> [arg] # 等待:載入、選擇器、超時
</type></deltay></deltax></y></x></toy></tox></fromy></fromx></key></values...></value></text></ref>會話管理
browse stop # 停止瀏覽器守護程序
browse status # 檢查守護程序狀態和已解析的模式
browse tab list # 列出所有開啟的標籤頁
browse tab switch <index-or-target-id> # 按索引或目標 ID 切換到標籤頁
browse tab close [index-or-target-id] # 關閉標籤頁
</index-or-target-id>典型工作流
如果環境很重要,請在第一個瀏覽器命令上放置 --local、--remote、--auto-connect 或 --cdp <port></port>。
browse open <url> --local</url>或browse open <url> --remote</url>— 導航到頁面browse snapshot— 讀取可訪問性樹以瞭解頁面結構並獲取元素引用browse click <ref></ref>/browse type <text></text>/browse fill <value></value>— 使用快照中的引用進行互動browse snapshot— 確認操作是否成功- 根據需要重複步驟 3-4
browse stop— 完成後關閉瀏覽器
快速示例
browse open https://example.com
browse snapshot # 檢視頁面結構 + 元素引用
browse click @0-5 # 點選引用為 0-5 的元素
browse get title
browse stop
模式對比
| 功能 | 本地 | Browserbase |
|---|---|---|
| 速度 | 更快 | 稍慢 |
| 設定 | 需要 Chrome | 需要 API 金鑰 |
| 複用現有本地 Cookie | 使用 `browse open | 不適用 |
| 經過驗證的瀏覽器 | 否 | 是(透過身份實現的 Browserbase 經過驗證的瀏覽器) |
| 驗證碼解決 | 否 | 是(自動 reCAPTCHA/hCaptcha) |
| 住宅代理 | 否 | 是(201 個國家/地區,地理定位) |
| 會話持久化 | 否 | 是(透過上下文持久化 Cookie/認證) |
| 最佳適用場景 | 開發/簡單頁面 | 受保護的網站、Browserbase 身份 + 經過驗證的訪問、生產環境爬取 |
最佳實踐
- 有意識地選擇本地策略:使用
browse open <url> --local</url>獲取乾淨狀態,使用browse open <url> --auto-connect</url>獲取現有本地憑據,使用browse open <url> --remote</url>處理受保護的網站 - 互動前始終先執行
browse open - 使用
browse snapshot檢查頁面狀態——它速度快且提供元素引用 - 僅在需要視覺上下文時截圖(佈局檢查、影象、除錯)
- 使用快照中的引用 進行點選/互動——例如,
browse click @0-5 - 完成後使用
browse stop以清理瀏覽器會話並清除環境覆蓋
故障排除
- “沒有活動頁面”:執行
browse stop,然後檢查browse status。如果仍顯示正在執行,請使用pkill -f "browse.*daemon"殺死殭屍守護程序,然後重試browse open - 未找到 Chrome:安裝 Chrome,如果您已經執行了可除錯的 Chrome,請使用
browse open <url> --auto-connect</url>,或者切換到browse open <url> --remote</url> - 操作失敗:執行
browse snapshot以檢視可用元素及其引用 - Browserbase 失敗:驗證是否設定了 API 金鑰
切換到遠端模式
當檢測到以下情況時切換到遠端模式:驗證碼(reCAPTCHA、hCaptcha、Turnstile)、機器人檢測頁面(“正在檢查您的瀏覽器...”)、HTTP 403/429、應該有內容的網站出現空頁面,或者使用者要求切換。
不要對簡單網站(文件、維基、公共 API、本地主機)進行切換。
browse open <url> --local # 乾淨的隔離本地瀏覽器
browse open <url> --auto-connect # 附加到現有的可除錯 Chrome
browse open <url> --remote # Browserbase 會話
</url></url></url>模式標誌在會話啟動時應用。browse stop 之後,下一次啟動將回退到基於環境變數的自動檢測。在守護程序執行時,使用 browse status 檢查已解析的模式和目標。
有關詳細示例,請參閱 EXAMPLES.md。有關 API 參考,請參閱 REFERENCE.md。
---
name: browser
description: Automate web browser interactions using natural language via CLI commands. Supports local and remote Browserbase sessions with CAPTCHA solving, residential proxies, and session persistence.
license: MIT
---
# Browser Automation
Automate browser interactions using the browse CLI with Claude.
## Setup check
Before running any browser commands, verify the CLI is available:
```bash
which browse || npm install -g browse
```
## Environment Selection (Local vs Remote)
The CLI supports explicit per-command environment flags. If you do nothing, the next session defaults to Browserbase when `BROWSERBASE_API_KEY` is set and to local otherwise.
### Local mode
- `browse open <url> --local` starts a clean isolated local browser
- `browse open <url> --auto-connect` attaches to an already-running debuggable Chrome; use `--local` when no debuggable Chrome is available
- `browse open <url> --cdp <port|url>` attaches to a specific CDP target
- Best for: development, localhost, trusted sites, and reproducible runs
### Remote mode (Browserbase)
- `browse open <url> --remote` starts a Browserbase session
- Without a local flag, Browserbase is also the default when `BROWSERBASE_API_KEY` is set
- Provides: Browserbase Identity, Verified browsers, automatic CAPTCHA solving, residential proxies, session persistence
- **Use remote mode when:** the target site has bot detection, CAPTCHAs, IP rate limiting, Cloudflare protection, or requires geo-specific access
- Get credentials at https://browserbase.com/settings
### When to choose which
- **Repeatable local testing / clean state**: `browse open <url> --local`
- **Reuse your local login/cookies**: `browse open <url> --auto-connect`
- **Simple browsing** (docs, wikis, public APIs): local mode is fine
- **Protected sites** (login walls, CAPTCHAs, anti-scraping): use remote mode
- **If local mode fails** with bot detection or access denied: switch to remote mode
## Commands
Most driver commands work across local, remote, and CDP sessions after the daemon starts.
### Navigation
```bash
browse open <url> # Go to URL
browse open <url> --local # Go to URL in a clean local browser
browse open <url> --remote # Go to URL in a Browserbase session
browse reload # Reload current page
browse back # Go back in history
browse forward # Go forward in history
```
### Page state (prefer snapshot over screenshot)
```bash
browse snapshot # Get accessibility tree with element refs (fast, structured)
browse screenshot --path <path> # Take visual screenshot (slow, uses vision tokens)
browse get url # Get current URL
browse get title # Get page title
browse get text <selector> # Get text content (use "body" for all text)
browse get html <selector> # Get HTML content of element
browse get value <selector> # Get form field value
```
Use `browse snapshot` as your default for understanding page state — it returns the accessibility tree with element refs you can use to interact. Only use `browse screenshot` when you need visual context (layout, images, debugging).
### Interaction
```bash
browse click <ref> # Click element by ref from snapshot (e.g., @0-5)
browse type <text> # Type text into focused element
browse fill <selector> <value> # Fill input; add --press-enter if Enter is needed
browse select <selector> <values...> # Select dropdown option(s)
browse press <key> # Press key (Enter, Tab, Escape, Cmd+A, etc.)
browse mouse drag <fromX> <fromY> <toX> <toY> # Drag from one point to another
browse mouse scroll <x> <y> <deltaX> <deltaY> # Scroll at coordinates
browse highlight <selector> # Highlight element on page
browse is visible <selector> # Check if element is visible
browse is checked <selector> # Check if element is checked
browse wait <type> [arg] # Wait for: load, selector, timeout
```
### Session management
```bash
browse stop # Stop the browser daemon
browse status # Check daemon status and resolved mode
browse tab list # List all open tabs
browse tab switch <index-or-target-id> # Switch to tab by index or target ID
browse tab close [index-or-target-id] # Close tab
```
### Typical workflow
If the environment matters, put `--local`, `--remote`, `--auto-connect`, or `--cdp <port|url>` on the first browser command.
1. `browse open <url> --local` or `browse open <url> --remote` — navigate to the page
2. `browse snapshot` — read the accessibility tree to understand page structure and get element refs
3. `browse click <ref>` / `browse type <text>` / `browse fill <selector> <value>` — interact using refs from snapshot
4. `browse snapshot` — confirm the action worked
5. Repeat 3-4 as needed
6. `browse stop` — close the browser when done
## Quick Example
```bash
browse open https://example.com
browse snapshot # see page structure + element refs
browse click @0-5 # click element with ref 0-5
browse get title
browse stop
```
## Mode Comparison
| Feature | Local | Browserbase |
|---------|-------|-------------|
| Speed | Faster | Slightly slower |
| Setup | Chrome required | API key required |
| Reuse existing local cookies | With `browse open <url> --auto-connect` | N/A |
| Verified browser | No | Yes (Browserbase Verified browser via Identity) |
| CAPTCHA solving | No | Yes (automatic reCAPTCHA/hCaptcha) |
| Residential proxies | No | Yes (201 countries, geo-targeting) |
| Session persistence | No | Yes (cookies/auth persist via contexts) |
| Best for | Development/simple pages | Protected sites, Browserbase Identity + Verified access, production scraping |
## Best Practices
1. **Choose the local strategy deliberately**: use `browse open <url> --local` for clean state, `browse open <url> --auto-connect` for existing local credentials, and `browse open <url> --remote` for protected sites
2. **Always `browse open` first** before interacting
3. **Use `browse snapshot`** to check page state — it's fast and gives you element refs
4. **Only screenshot when visual context is needed** (layout checks, images, debugging)
5. **Use refs from snapshot** to click/interact — e.g., `browse click @0-5`
6. **`browse stop`** when done to clean up the browser session and clear the env override
## Troubleshooting
- **"No active page"**: Run `browse stop`, then check `browse status`. If it still says running, kill the zombie daemon with `pkill -f "browse.*daemon"`, then retry `browse open`
- **Chrome not found**: Install Chrome, use `browse open <url> --auto-connect` if you already have a debuggable Chrome running, or switch to `browse open <url> --remote`
- **Action fails**: Run `browse snapshot` to see available elements and their refs
- **Browserbase fails**: Verify API key is set
## Switching to Remote Mode
Switch to remote when you detect: CAPTCHAs (reCAPTCHA, hCaptcha, Turnstile), bot detection pages ("Checking your browser..."), HTTP 403/429, empty pages on sites that should have content, or the user asks for it.
Don't switch for simple sites (docs, wikis, public APIs, localhost).
```bash
browse open <url> --local # clean isolated local browser
browse open <url> --auto-connect # attach to existing debuggable Chrome
browse open <url> --remote # Browserbase session
```
Mode flags are applied when a session starts. After `browse stop`, the next start falls back to env-var-based auto detection. Use `browse status` to inspect the resolved mode and target while the daemon is running.
For detailed examples, see [EXAMPLES.md](EXAMPLES.md).
For API reference, see [REFERENCE.md](REFERENCE.md).





首頁
