Communitygithub.com

w-winter/dot314

通過 CLI 控制 Chrome 瀏覽器以進行測試、自動化和除錯。當使用者需要瀏覽器自動化、螢幕截圖、表單填寫、頁面檢查、網路/CPU 模擬、DevTools 串流,或透過 ChatGPT/Gemini/Perplexity/Grok/AI Studio 進行 AI 查詢時使用。

dot314 是什麼?

此技能透過 CLI 或 Unix socket 提供全面的 Chrome 瀏覽器控制能力,支援 WSL2、macOS 和 Windows 等多種平台。除基本的瀏覽器自動化操作(如導航、點擊、輸入文字和螢幕截圖)外,還支援進階功能如遠端控制、動畫審計、網路/CPU 模擬和 DevTools 串流。其獨特之處在於整合多種 AI 助手,可透過瀏覽器登入會話直接查詢 ChatGPT、Gemini、Perplexity、Grok 和 AI Studio,無需另外的 API 金鑰。此外,Oracle 子系統提供持久性任務管理,適用於長時間運行的程式碼審查,支援斷電恢復和工作追蹤。作者精心設計了詳細的除錯工作流程和驗證機制,確保在 UI 變更或模型更新時仍然可靠運作。

相容平台✓Claude Code~Codex CLI~Cursor✓Gemini CLI
npx skills add https://github.com/w-winter/dot314/tree/HEAD/skills/surf

在你喜歡的 AI 中提問

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

說明文件

Surf 瀏覽器自動化

透過 CLI 或 Unix socket 控制 Chrome 瀏覽器。

原生主機 / Socket 注意事項

對於搭配 Windows Chrome 的 WSL2,請在 WSL2 內執行 surf install <extension-id>。Surf 會偵測 WSL2,並寫入 Windows 端的原生訊息傳遞清單,以及啟動 WSL 主機的包裝程式。僅在 WSLg 內執行 Linux 瀏覽器時,才使用 surf install <extension-id> --target linux。

在 macOS 上,Chrome 會在 ~/Library/Application Support/Google/Chrome/NativeMessagingHosts/surf.browser.host.json 尋找原生訊息傳遞清單。如果原生訊息傳遞失敗,請確認該檔案存在、其 allowed_origins 的擴充功能 ID 與 chrome://extensions 相符,然後重新執行 surf install <extension-id>,重新啟動 Chrome,重新載入擴充功能,並檢查擴充功能的 service worker 控制台。

如果命令回報 Socket connect failed,請先執行 surf doctor,然後檢查 Attempted socket: 這一行。預設 socket 在 macOS/Linux/WSL2 上是 /tmp/surf.sock,在 Windows 上是 //./pipe/surf。如果已設定 SURF_SOCKET,則瀏覽器啟動的主機和執行 surf 的 shell 必須使用相同的值。

遠端 Surf

遠端客戶端需要每個客戶端的憑證;僅有 Tailnet 可達性不足以作為授權。在 POSIX 瀏覽器主機上,請在安裝監聽器之前授權客戶端:

surf remote authorize agent-macbook --output ~/agent-macbook.surf-credential.json
surf install <extension-id> --listen 100.101.102.103:4321
surf remote list

將權限為 0600 的憑證透過安全通道移動到客戶端。它授予完整的受信任 Surf 權限。明確使用它,或透過 SURF_REMOTE 和 SURF_REMOTE_CREDENTIAL 使用:

surf --remote 100.101.102.103:4321 \
  --remote-credential ~/.config/surf/agent-macbook.json \
  page.read

surf remote revoke agent-macbook  # 在瀏覽器主機上執行

遠端路徑預設是客戶端本機的。local:./file 是明確的客戶端本機語法;只有 remote:/absolute/path 可以直接存取瀏覽器主機。遠端傳輸支援一次上傳或 ChatGPT/Gemini 輸入,以及一次螢幕截圖、網路匯出或 Gemini 圖片輸出。限制為每個檔案 256 MiB、每個連線 512 MiB 和 32 個檔案,以及 256 KiB 的解碼區塊。不支援 record、aistudio.build、螢幕截圖目錄、目錄和多檔案輸入的遠端操作。成功的動作螢幕截圖和失敗的 --auto-capture 診斷會傳輸回客戶端本機路徑。

CLI 快速參考

surf --help                    # 完整說明
surf <group>                   # 群組說明 (tab, scroll, page, wait, dialog, emulate, form, perf, ai)
surf --help-full               # 所有命令
surf --find <term>             # 搜尋工具
surf --help-topic <topic>      # 主題指南 (refs, semantic, frames, devices, windows)

核心工作流程

# 1. 導航到頁面
surf navigate "https://example.com"

# 2. 讀取頁面以取得元素參考
surf page.read

# 3. 依參考或座標點擊
surf click --ref "e1"
surf click --x 100 --y 200

# 4. 輸入文字
surf type --text "hello"

# 5. 全頁截圖
surf screenshot --full-page --output /tmp/shot.png

# 以 JSON 檢查動畫/樣式變更
surf animate-audit --selector ".thing" --duration 2000 --fps 10

AI 助手(無需 API 金鑰)

使用您瀏覽器中已登入的會話來查詢 AI 模型。必須在 Chrome 中登入對應的服務。

ChatGPT

surf chatgpt "explain this code"
surf chatgpt "summarize" --with-page              # 包含當前頁面內容
surf chatgpt "review" --model gpt-5.5             # 指定模型
surf chatgpt "analyze" --file document.pdf        # 附帶檔案

Oracle

使用 surf chatgpt 進行快速的一次性問題。使用 surf oracle 進行需要持久性任務、明確模型和努力程度選擇、檔案內容、恢復或後續回合的長時間運作或 Pro 編碼諮詢。Oracle 僅限本機使用。

對於代理工作流程,請在分派後分離,並保留回傳的 .id:

surf oracle ask "Review this change and identify release risks" \
  --files "src/**/*.ts" --files "package.json" \
  --model gpt-5.5 --effort pro --detach --json

surf oracle status <job-id> --json
surf oracle result <job-id> --json
# 或者讓 Surf 持續輪詢直到捕獲:
surf oracle result <job-id> --wait --json

status 讀取持久化狀態,無需觸及 Chrome。result 嘗試收取答案,並在其狀態為 captured 時回傳包含 response 的任務物件。等待期間按下 Ctrl-C 會以狀態碼 130 退出,並印出 Recover with: surf oracle result <id>。一旦任務處於 awaiting 狀態,持久化的 ChatGPT 對話 URL 就是其持久性金鑰,因此 surf oracle result <id> 可以在 CLI 退出、原生主機重新啟動或 Chrome 重新啟動後,透過重新開啟該對話來恢復。

請將 Pro 配額視為稀缺資源。Oracle 絕不會隱含地選擇 Pro;請使用 --model pro 或 --effort pro 來要求。ChatGPT 模型別名包括 instant、thinking、pro、gpt-5.5 和 gpt-5.6-sol。接受的 --effort 值為 light、standard、extended、heavy 和 pro。要求的模型和努力程度選擇會在提交前回讀,無法驗證的選擇會失敗並回報 model_verification_failed,而不是靜默繼續。容量限制為一個非終端的 Oracle 任務。capacity 錯誤會包含進行中的任務 ID;請輪詢該任務或等待其完成,而不是再次提交相同的諮詢。

當作為 Pi 擴充功能載入時,如果執行環境暴露了該橋接,Surf 也會註冊一個 surf-oracle 外部任務提供者。該提供者將 start、status、result、reattach 和 follow 映射到持久的 Surf Oracle 任務。它會回傳對話 URL、要求和驗證的模型與努力程度、提示摘要、結果文字以及失敗詳細資訊。reattach 僅透過 ID 收取現有任務;它永遠不會再次提交提示。

內容來自可重複的 --files glob 模式。當 glob 沒有匹配到任何內容,或匹配到的檔案無法讀取、為二進位檔案或無效的 UTF-8 時,Surf 會安全地失敗。它也會封鎖 gitignored 檔案以及檔名符合 .env*、*.pem、*.key、id_rsa*、id_ed25519*、*.p12、*.pfx、credentials* 或 secrets* 的檔案。只有在您有意審查這些檔案後,才使用 --allow-sensitive;它會覆寫封鎖,而不是隱藏內容。最多 60,000 個證據字元的內容會內嵌插入,而更大的內容則會變成一個私有的文字附件。組合清單會記錄每個檔案的路徑、位元組數、SHA-256、內嵌或套件處置方式以及拒絕清單結果。

使用 follow 繼續已捕獲的諮詢。使用每個回合回傳的 ID 進行下一回合:

surf oracle follow <job-id> "Challenge your recommendation. What could invalidate it?" --detach --json
surf oracle result <follow-job-id> --wait --json
surf oracle follow <follow-job-id> "Give the final decision and concrete next steps." --detach --json

Gemini

surf gemini "explain quantum computing"
surf gemini "summarize" --with-page               # 包含頁面內容
surf gemini "analyze" --file data.csv             # 附加檔案
surf gemini "a robot surfing" --generate-image /tmp/robot.png
surf gemini "add sunglasses" --edit-image photo.jpg --output out.jpg
surf gemini "summarize" --youtube "https://youtube.com/..."
surf gemini "hello" --model gemini-3.5-flash      # 模型:gemini-3.1-pro (預設), gemini-3.5-flash, gemini-3.1-flash-lite
surf gemini "wide banner" --generate-image /tmp/banner.png --aspect-ratio 16:9

Perplexity

surf perplexity "what is quantum computing"
surf perplexity "explain this page" --with-page   # 包含頁面內容
surf perplexity "deep dive" --mode research       # 研究模式 (Pro)
surf perplexity "latest news" --model sonar       # 模型選擇 (Pro)

Grok (透過 x.com - 需要在 Chrome 中登入 X.com)

surf grok "what are the latest AI trends on X"    # 搜尋 X 貼文
surf grok "analyze @username recent activity"     # 個人資料分析
surf grok "summarize this page" --with-page       # 包含頁面內容
surf grok "find viral AI posts" --deep-search     # DeepSearch 模式
surf grok "quick question" --model fast           # 模型:auto, fast, expert, grok-4.20-beta

對於需要分類結果和完整貼文 URL 可追溯性的詳盡、多角度 X 研究,請改用 deep-x-research 技能(skills/deep-x-research/),而不是單次 Grok 查詢。

Grok 驗證與疑難排解:

# 驗證 Grok UI 並檢查可用模型(不發送查詢)
surf grok --validate

# 如果模型已更改,將發現的模型儲存到 surf.json 設定中
surf grok --validate --save-models

AI Studio (透過 aistudio.google.com - 需要在 Chrome 中登入 Google)

surf aistudio "explain quantum computing"
surf aistudio "redteam this" --with-page          # 包含當前頁面內容
surf aistudio "quick answer" --model gemini-3-flash-preview  # 模型選擇
surf aistudio "analyze" --timeout 600             # 自訂超時 (預設:300s)

為什麼選擇 AI Studio 而不是 Gemini? AI Studio 可以存取限制較少的 Gemini 模型。對於 Gemini 3 Pro,某些提示的差異可能很顯著。缺點:Pro 和 Flash 模型有嚴格的每日速率限制。

模型選擇是盡力而為: 傳遞任何 AI Studio 模型 ID(例如 gemini-3.1-pro-preview、gemini-3-flash-preview、gemini-flash-lite-latest)。如果找不到該模型,AI Studio 會使用 UI 中上次選擇的模型。

AI Studio 應用程式建置器

surf aistudio.build "build a portfolio site"
surf aistudio.build "todo app" --model gemini-3.1-pro-preview   # 模型覆寫
surf aistudio.build "crm dashboard" --output ./out              # 將 zip 解壓縮到目錄
surf aistudio.build "game" --keep-open --timeout 600            # 保持分頁開啟,10 分鐘超時

自動化 AI Studio 在 aistudio.google.com/apps 的應用程式建置器。輸入您的提示,按一下「建置」,等待完成,下載產生的 zip 檔案,並選擇性地解壓縮。

  • --output <dir> 將 zip 解壓縮到目錄
  • --model <id> 覆寫進階設定中的模型
  • --timeout <seconds> 建置超時(預設:600s)
  • --keep-open 在完成後保持 AI Studio 分頁開啟

回傳 zipPath、extractedPath、model、buildDuration 和 tookMs。

AI 工具疑難排解

當 AI 查詢失敗時,請檢查這些常見問題:

  1. 未登入:錯誤 "login required" 表示您需要在 Chrome 中登入服務(chatgpt.com、gemini.google.com、perplexity.ai、x.com 或 aistudio.google.com)
  2. 模型選擇失敗:UI 可能已變更。執行 surf grok --validate 檢查
  3. 回應超時:推理密集型模型(ChatGPT o1、Grok Expert)可能需要超過 45 秒。AI Studio 建置可能需要數分鐘。
  4. 找不到元素:服務的 UI 已變更。檢查 surf-cli 更新

代理的除錯工作流程:

# 1. 檢查服務是否可存取且 UI 是否有效
surf grok --validate

# 2. 如果模型不匹配,更新本機設定
surf grok --validate --save-models

# 3. 使用驗證輸出中的明確模型名稱重試
surf grok "query" --model <model-from-validation>

# 4. 如果仍然失敗,嘗試使用更長的超時時間
surf grok "query" --timeout 600

分頁管理

surf tab.list
surf tab.new "https://google.com"
surf tab.switch 12345
surf tab.close 12345
surf tab.move 12345 --to-window 67890
surf tab.reload                # 重新載入當前分頁

# 命名分頁(別名)
surf tab.name myapp            # 為當前分頁命名
surf tab.switch myapp          # 依名稱切換
surf tab.named                 # 列出已命名的分頁
surf tab.unname myapp          # 移除名稱

# 分頁群組
surf tab.group                 # 建立/加入到分頁群組
surf tab.ungroup               # 從群組移除
surf tab.groups                # 列出所有分頁群組

視窗管理

surf window.list                              # 列出所有視窗
surf resize 1280 720                         # 調整當前瀏覽器視窗大小
surf resize 1280                             # 僅設定當前視窗寬度
surf window.list --tabs                       # 包含分頁詳細資訊
surf window.new                               # 新視窗
surf window.new --url "https://example.com"   # 帶有 URL 的新視窗
surf window.new --incognito                   # 新的無痕視窗
surf window.new --unfocused                   # 不聚焦新視窗
surf window.focus 12345                       # 依 ID 聚焦視窗
surf window.close 12345                       # 關閉視窗
surf window.resize --id 123 --width 1920 --height 1080
surf window.resize --id 123 --state maximized # 狀態:normal, minimized, maximized, fullscreen

多代理隔離:

# 為一個代理建立單獨的視窗,並持續使用其 ID
surf window.new "https://example.com"
surf --window-id 123 tab.list
surf --window-id 123 go "https://other.com"

# 將工作固定到特定分頁,或為其命名以便更輕鬆地交接
surf read --tab-id 456
surf tab.name agent-a --tab-id 456
surf tab.switch agent-a

使用 window.new、--window-id、--tab-id 和命名分頁,讓並行代理保持在獨立的目標上。Surf 會透過基於檔案的鎖定,將每個 socket 的非串流瀏覽器 CLI 請求序列化,因此共享一個原生主機的代理會等待,而不是交錯執行命令。僅在有意繞過時使用 --no-lock。對於嚴格隔離,請使用各自的 SURF_SOCKET 值執行獨立的瀏覽器/設定檔實例和原生主機;每個 socket 都有自己的鎖定。Surf 尚未提供 session.new、會話 ID 或獨立的、每個代理的 CDP 會話。

輸入方法

# CDP 方法(真實事件)在當前焦點處輸入
surf type --text "hello"
surf click --x 100 --y 200

# 選擇器/參考目標使用具備 frame 感知能力的 DOM 輸入
surf type "hello" --into "#input"
surf type "hello" --ref e5

# 按鍵
surf key Enter
surf key "cmd+a"
surf key.repe

…

[因篇幅限制而截斷]

相關技能