playwright-debug
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePlaywright MCP Live Debugging
Playwright MCP 实时调试
Connect to a running VoiceTree Electron app for live debugging via browser automation.
通过浏览器自动化连接到运行中的VoiceTree Electron应用进行实时调试。
Quick Start (3 steps)
快速开始(3步)
1. Start Electron in debug mode
1. 启动Electron调试模式
bash
cd webapp && npm run electron:debugThis starts Electron with CDP enabled on port 9222 and automatically calls once the renderer is ready — loading the project and spawning 3 debug terminals.
prettySetupAppForElectronDebugging()example_smallRun with a bash timeout (e.g. 30s) since this is a long-running dev server.
bash
cd webapp && npm run electron:debug此命令会启动Electron并在9222端口启用CDP,同时会在渲染器就绪后自动调用——加载项目并生成3个调试终端。
prettySetupAppForElectronDebugging()example_small由于这是一个长期运行的开发服务器,可搭配bash超时命令运行(例如30秒)。
2. Verify CDP is ready
2. 验证CDP已就绪
bash
curl -s http://localhost:9222/json/versionShould return JSON with .
"Browser": "Chrome/..."bash
curl -s http://localhost:9222/json/version应返回包含的JSON数据。
"Browser": "Chrome/..."3. Go straight to inspecting — do NOT navigate
3. 直接开始检查——请勿导航
The app is already loaded with the project and debug terminals. Do not run or — this would force-refresh and destroy the loaded state. Instead, jump directly to:
browser_navigatepage.goto()javascript
// browser_evaluate — check cytoscape nodes
const cy = window.cytoscapeInstance;
JSON.stringify({ nodeCount: cy.nodes().length, edgeCount: cy.edges().length });Use or for visual inspection.
browser_snapshotbrowser_take_screenshot应用已加载项目和调试终端。不要运行或——这会强制刷新并破坏已加载的状态。请直接使用以下代码:
browser_navigatepage.goto()javascript
// browser_evaluate — 检查cytoscape节点
const cy = window.cytoscapeInstance;
JSON.stringify({ nodeCount: cy.nodes().length, edgeCount: cy.edges().length });使用或进行可视化检查。
browser_snapshotbrowser_take_screenshotOpening a specific project (optional)
打开指定项目(可选)
If you need a specific project instead of the test fixture:
javascript
await window.electronAPI.main.initializeProject('/path/to/folder');如果需要加载特定项目而非测试示例:
javascript
await window.electronAPI.main.initializeProject('/path/to/folder');Available Tools
可用工具
| Tool | Purpose |
|---|---|
| Get accessibility tree of current page |
| Click elements by ref |
| Hover over elements |
| Type into inputs |
| Run JavaScript in page context |
| Switch between tabs |
| Wait for text/elements |
| Capture visual screenshot |
| 工具 | 用途 |
|---|---|
| 获取当前页面的可访问性树 |
| 通过引用点击元素 |
| 悬停在元素上 |
| 在输入框中输入内容 |
| 在页面上下文运行JavaScript |
| 在标签页之间切换 |
| 等待文本/元素加载 |
| 捕获可视化截图 |
Accessing App APIs
访问应用API
The app exposes with useful methods:
window.electronAPIjavascript
// Via browser_evaluate
Object.keys(window.electronAPI.main)
// Key methods:
window.electronAPI.main.prettySetupAppForElectronDebugging() // Spawn debug terminals
window.electronAPI.main.initializeProject(path) // Open a folder
window.electronAPI.main.getGraph() // Get graph data
window.electronAPI.main.getNode(id) // Get node details
window.electronAPI.main.loadSettings() // App settings应用暴露了接口,包含实用方法:
window.electronAPIjavascript
// 通过browser_evaluate调用
Object.keys(window.electronAPI.main)
// 核心方法:
window.electronAPI.main.prettySetupAppForElectronDebugging() // 生成调试终端
window.electronAPI.main.initializeProject(path) // 打开指定文件夹
window.electronAPI.main.getGraph() // 获取图数据
window.electronAPI.main.getNode(id) // 获取节点详情
window.electronAPI.main.loadSettings() // 加载应用设置Cytoscape Instance
Cytoscape实例
Access the graph directly via :
window.cytoscapeInstancejavascript
// Get all nodes in the graph
const cy = window.cytoscapeInstance;
cy.nodes().map(n => ({ id: n.id(), isContext: n.data('isContextNode') }));
// Get node count
cy.nodes().length;可通过直接访问图实例:
window.cytoscapeInstancejavascript
// 获取图中所有节点
const cy = window.cytoscapeInstance;
cy.nodes().map(n => ({ id: n.id(), isContext: n.data('isContextNode') }));
// 获取节点数量
cy.nodes().length;CRITICAL: Do NOT navigate or refresh the app
重要提示:请勿导航或刷新应用
electron:debug- Run /
browser_navigate— this will force-refresh the app and lose all loaded statepage.goto() - Hit in the browser — same problem
/json
Instead, go straight to to inspect the page state (e.g. query cytoscape nodes, check DOM elements). Use or for visual inspection.
browser_evaluatebrowser_snapshotbrowser_take_screenshotelectron:debug- 运行/
browser_navigate—— 这会强制刷新应用并丢失所有已加载状态page.goto() - 在浏览器中访问—— 会导致同样的问题
/json
请直接使用来检查页面状态(例如查询cytoscape节点、检查DOM元素)。使用或进行可视化检查。
browser_evaluatebrowser_snapshotbrowser_take_screenshotCRITICAL: Be surgical when killing Electron processes
重要提示:精准终止Electron进程
VoiceTree itself runs as an Electron process. A blanket or on all Electron PIDs will kill your own host app. To kill only the debug Electron:
pkill -f electronkill -9bash
undefinedVoiceTree本身作为Electron进程运行。使用或终止所有Electron进程会同时关闭你的宿主应用。仅终止调试用Electron的方法:
pkill -f electronkill -9bash
undefinedFind ONLY the process listening on port 9222
仅查找监听9222端口的进程
lsof -i :9222 -sTCP:LISTEN
lsof -i :9222 -sTCP:LISTEN
Then kill that specific PID
然后终止该特定PID
kill <pid>
Never use `pkill -f electron` or kill Electron PIDs found via `lsof -i :9222` without the `-sTCP:LISTEN` filter — connected clients (including your own app) also show up.kill <pid>
切勿使用`pkill -f electron`,或在未添加`-sTCP:LISTEN`过滤器的情况下终止`lsof -i :9222`找到的Electron PID —— 已连接的客户端(包括你自己的应用)也会被列出。Troubleshooting
故障排查
| Issue | Solution |
|---|---|
| Connection refused | Ensure Electron started with |
| Timeout on first connect | Retry - first connection can be slow |
| Wrong tab selected | |
| Native dialog opened | Use JavaScript APIs instead - native dialogs can't be automated |
| Old Electron still running | |
| 问题 | 解决方案 |
|---|---|
| 连接被拒绝 | 确保使用 |
| 首次连接超时 | 重试 —— 首次连接可能较慢 |
| 选中了错误的标签页 | 使用 |
| 弹出原生对话框 | 使用JavaScript API替代 —— 原生对话框无法被自动化 |
| 旧的Electron进程仍在运行 | 执行 |
Architecture
架构
Claude Code → @playwright/mcp --cdp-endpoint http://localhost:9222 → CDP → Electron App → VoiceTree WebappClaude Code → @playwright/mcp --cdp-endpoint http://localhost:9222 → CDP → Electron 应用 → VoiceTree 网页应用Notes
注意事项
- CDP only accesses renderer process, not Electron main process
- Hot reload works - no restart needed on code changes
- Native file dialogs cannot be automated - use instead
electronAPI.main.initializeProject() - Only one debug session at a time (port 9222 hardcoded)
- CDP仅能访问渲染进程,无法访问Electron主进程
- 支持热重载 —— 代码变更后无需重启
- 原生文件对话框无法被自动化 —— 请使用替代
electronAPI.main.initializeProject() - 同一时间仅支持一个调试会话(端口9222为硬编码)