Communitygithub.com

Electron 桌面應用自動化

使用 agent-browser 透過 Chrome DevTools Protocol 自動化 Electron 桌面應用程式(如 VS Code、Slack、Discord、Figma、Notion、Spotify 等)。當使用者需要與 Electron 應用程式互動、自動化桌面應用、連接到正在運行的應用、控制原生應用或測試 Electron 應用程式時使用。

Electron 桌面應用自動化 是什麼?

此技能提供透過 agent-browser 自動化任何 Electron 桌面應用程式的完整解決方案。由於 Electron 應用程式建構在 Chromium 之上,它們可透過 `--remote-debugging-port` 標誌暴露 Chrome DevTools Protocol (CDP) 端口,讓 agent-browser 能夠連接並執行標準的快照-互動工作流程。它支援 macOS、Linux 和 Windows 平台,並提供啟動應用程式、連接 CDP 端口、管理多個分頁/視窗(包括 `<webview>` 元素)、擷取螢幕截圖、填寫表單以及同時控制多個應用程式的詳細指令。常見的疑難排解提示和支援的應用程式清單(如 Slack、VS Code、Discord、Figma、Notion、Spotify 等)也已涵蓋,以確保順利自動化。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/vercel-labs/agent-browser/tree/main/skill-data/electron

在你喜歡的 AI 中提問

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

說明文件

Electron 應用程式自動化

使用 agent-browser 自動化任何 Electron 桌面應用程式。Electron 應用程式建構在 Chromium 之上,並暴露一個 Chrome DevTools Protocol (CDP) 端口,agent-browser 可以連接到該端口,從而實現與網頁相同的快照-互動工作流程。

核心工作流程

  1. 啟動 啟用遠端除錯功能的 Electron 應用程式
  2. 連接 agent-browser 到 CDP 端口
  3. 快照 以發現可互動元素
  4. 互動 使用元素引用
  5. 重新快照 在導航或狀態變更後
# 使用遠端除錯功能啟動 Electron 應用程式
open -a "Slack" --args --remote-debugging-port=9222

# 將 agent-browser 連接到應用程式
agent-browser connect 9222

# 從這裡開始標準工作流程
agent-browser snapshot -i
agent-browser click @e5
agent-browser screenshot slack-desktop.png

使用 CDP 啟動 Electron 應用程式

每個 Electron 應用程式都支援 --remote-debugging-port 標誌,因為它內建於 Chromium 中。

macOS

# Slack
open -a "Slack" --args --remote-debugging-port=9222

# VS Code
open -a "Visual Studio Code" --args --remote-debugging-port=9223

# Discord
open -a "Discord" --args --remote-debugging-port=9224

# Figma
open -a "Figma" --args --remote-debugging-port=9225

# Notion
open -a "Notion" --args --remote-debugging-port=9226

# Spotify
open -a "Spotify" --args --remote-debugging-port=9227

Linux

slack --remote-debugging-port=9222
code --remote-debugging-port=9223
discord --remote-debugging-port=9224

Windows

"C:\Users\%USERNAME%\AppData\Local\slack\slack.exe" --remote-debugging-port=9222
"C:\Users\%USERNAME%\AppData\Local\Programs\Microsoft VS Code\Code.exe" --remote-debugging-port=9223

重要: 如果應用程式已在執行,請先將其退出,然後使用該標誌重新啟動。--remote-debugging-port 標誌必須在啟動時存在。

連接

# 連接到特定端口
agent-browser connect 9222

# 或在每個命令上使用 --cdp
agent-browser --cdp 9222 snapshot -i

# 自動發現正在執行的基於 Chromium 的應用程式
agent-browser --auto-connect snapshot -i

在 connect 之後,所有後續命令都針對已連接的應用程式,無需 --cdp。

分頁管理

Electron 應用程式通常有多個視窗或網頁視圖。使用分頁命令來列出和切換它們:

# 列出所有可用的目標(視窗、網頁視圖等)
agent-browser tab

# 按索引切換到特定分頁
agent-browser tab 2

# 按 URL 模式切換
agent-browser tab --url "*settings*"

Webview 支援

Electron <webview> 元素會自動被發現,並且可以像普通頁面一樣被控制。Webview 在分頁清單中作為單獨的目標出現,類型為 type: "webview":

# 連接到正在執行的 Electron 應用程式
agent-browser connect 9222

# 列出目標 -- webview 與頁面一起出現
agent-browser tab
# 範例輸出:
#   0: [page]    Slack - 主視窗     https://app.slack.com/
#   1: [webview] 嵌入內容        https://example.com/widget

# 切換到 webview
agent-browser tab 1

# 正常與 webview 互動
agent-browser snapshot -i
agent-browser click @e3
agent-browser screenshot webview.png

注意: Webview 支援透過原始 CDP 連接運作。

常見模式

檢查和導航應用程式

open -a "Slack" --args --remote-debugging-port=9222
sleep 3  # 等待應用程式啟動
agent-browser connect 9222
agent-browser snapshot -i
# 讀取快照輸出以識別 UI 元素
agent-browser click @e10  # 導航到某個部分
agent-browser snapshot -i  # 導航後重新快照

擷取桌面應用程式的螢幕截圖

agent-browser connect 9222
agent-browser screenshot app-state.png
agent-browser screenshot --full full-app.png
agent-browser screenshot --annotate annotated-app.png

從桌面應用程式提取資料

agent-browser connect 9222
agent-browser snapshot -i
agent-browser get text @e5
agent-browser snapshot --json > app-state.json

在桌面應用程式中填寫表單

agent-browser connect 9222
agent-browser snapshot -i
agent-browser fill @e3 "搜尋查詢"
agent-browser press Enter
agent-browser wait 1000
agent-browser snapshot -i

同時執行多個應用程式

使用命名會話來同時控制多個 Electron 應用程式:

# 連接到 Slack
agent-browser --session slack connect 9222

# 連接到 VS Code
agent-browser --session vscode connect 9223

# 獨立與每個應用程式互動
agent-browser --session slack snapshot -i
agent-browser --session vscode snapshot -i

色彩方案

透過 CDP 連接時的預設色彩方案可能是 light。要保持深色模式:

agent-browser connect 9222
agent-browser --color-scheme dark snapshot -i

或全域設定:

AGENT_BROWSER_COLOR_SCHEME=dark agent-browser connect 9222

疑難排解

"連接被拒絕" 或 "無法連接"

  • 確保應用程式是使用 --remote-debugging-port=NNNN 啟動的
  • 如果應用程式已在執行,請退出並使用該標誌重新啟動
  • 檢查端口是否被其他行程使用:lsof -i :9222

應用程式啟動但連接失敗

  • 啟動後等待幾秒再連接(sleep 3)
  • 某些應用程式需要時間來初始化其 webview

快照中未出現元素

  • 應用程式可能使用多個 webview。使用 agent-browser tab 列出目標並切換到正確的目標

無法在輸入欄位中輸入文字

  • 嘗試使用 agent-browser keyboard type "text" 在目前焦點處輸入文字,無需選擇器
  • 某些 Electron 應用程式使用自訂輸入元件;使用 agent-browser keyboard inserttext "text" 繞過按鍵事件

支援的應用程式

任何建構在 Electron 上的應用程式皆可運作,包括:

  • 通訊: Slack、Discord、Microsoft Teams、Signal、Telegram Desktop
  • 開發: VS Code、GitHub Desktop、Postman、Insomnia
  • 設計: Figma、Notion、Obsidian
  • 媒體: Spotify、Tidal
  • 生產力: Todoist、Linear、1Password

如果應用程式是使用 Electron 建構的,它支援 --remote-debugging-port,並且可以使用 agent-browser 進行自動化。

Individual skills in this repo

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

agent-browser

Browser automation CLI for AI agents. Use when the user needs to interact with websites, including navigating pages, filling forms, clicking buttons, taking screenshots, extracting data, testing web apps, or automating any browser task. Triggers include requests to

vercel-labs/agentcore

Run agent-browser on AWS Bedrock AgentCore cloud browsers. Use when the user wants to use AgentCore, run browser automation on AWS, use a cloud browser with AWS credentials, or needs a managed browser session backed by AWS infrastructure. Triggers include "use agentcore", "run on AWS", "cloud browser with AWS", "bedrock browser", "agentcore session", or any task requiring AWS-hosted browser automation.

vercel-labs/derive-client

Reverse-engineer a website's internal API by recording browser traffic into a HAR file, then generate a standalone client or CLI that calls the endpoints directly, with no browser needed after the first recording. Use when asked to "derive a client", "build a CLI for <site>", "reverse engineer this site's API", "record network requests", "turn this site into an API", or when the same site will be automated repeatedly and direct HTTP calls would beat driving the browser every time.

vercel-labs/dogfood

Systematically explore and test a web application to find bugs, UX issues, and other problems. Use when asked to "dogfood", "QA", "exploratory test", "find issues", "bug hunt", "test this app/site/platform", or review the quality of a web application. Produces a structured report with full reproduction evidence -- step-by-step screenshots, repro videos, and detailed repro steps for every issue -- so findings can be handed directly to the responsible teams.

vercel-labs/protected-vercel-deployments

Access and test Vercel deployments protected by Vercel Authentication, SSO, or Deployment Protection with agent-browser. Use when a preview or production URL redirects to a Vercel login page, returns a protection 401 or 403, or needs short-lived Trusted Sources OIDC authentication instead of a static bypass secret or public exception.

vercel-labs/slack

Interact with Slack workspaces using browser automation. Use when the user needs to check unread channels, navigate Slack, send messages, extract data, find information, search conversations, or automate any Slack task. Triggers include "check my Slack", "what channels have unreads", "send a message to", "search Slack for", "extract from Slack", "find who said", or any task requiring programmatic Slack interaction.

vercel-labs/vercel-sandbox

Run agent-browser + Chrome inside Vercel Sandbox microVMs for browser automation from any Vercel-deployed app. Use when the user needs browser automation in a Vercel app (Next.js, SvelteKit, Nuxt, Remix, Astro, etc.), wants to run headless Chrome without binary size limits, needs persistent browser sessions across commands, or wants ephemeral isolated browser environments. Triggers include "Vercel Sandbox browser", "microVM Chrome", "agent-browser in sandbox", "browser automation on Vercel", or any task requiring Chrome in a Vercel Sandbox.

vercel-labs/webmcp-gen

Build and validate experimental WebMCP tools for an existing web page. Use when an agent needs to expose a site's real workflows as page tools, create webmcp.init.js, define deterministic checks, or compare WebMCP with accessibility-tree automation.

相關技能