惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

NISL@THU
NISL@THU
Security Archives - TechRepublic
Security Archives - TechRepublic
T
Threatpost
Cloudbric
Cloudbric
H
Heimdal Security Blog
P
Privacy International News Feed
www.infosecurity-magazine.com
www.infosecurity-magazine.com
T
Tor Project blog
A
Arctic Wolf
W
WeLiveSecurity
SecWiki News
SecWiki News
S
Security Affairs
Schneier on Security
Schneier on Security
PCI Perspectives
PCI Perspectives
Simon Willison's Weblog
Simon Willison's Weblog
K
Kaspersky official blog
P
Privacy & Cybersecurity Law Blog
AWS News Blog
AWS News Blog
T
The Exploit Database - CXSecurity.com
V2EX - 技术
V2EX - 技术
AI
AI
Google DeepMind News
Google DeepMind News
Stack Overflow Blog
Stack Overflow Blog
博客园 - 司徒正美
有赞技术团队
有赞技术团队
C
Cybersecurity and Infrastructure Security Agency CISA
腾讯CDC
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 聂微东
H
Hacker News: Front Page
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Hugging Face - Blog
Hugging Face - Blog
The Hacker News
The Hacker News
阮一峰的网络日志
阮一峰的网络日志
Microsoft Security Blog
Microsoft Security Blog
WordPress大学
WordPress大学
月光博客
月光博客
博客园 - 【当耐特】
Recorded Future
Recorded Future
O
OpenAI News
Hacker News: Ask HN
Hacker News: Ask HN
Scott Helme
Scott Helme
N
News and Events Feed by Topic
Help Net Security
Help Net Security
GbyAI
GbyAI
Google DeepMind News
Google DeepMind News
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Y
Y Combinator Blog
Martin Fowler
Martin Fowler
小众软件
小众软件

icodex | 前端技术博客 | 专注 React、TypeScript、AI 与性能优化 Blog

2026-07-26-前端与AI技术周报 2026-07-18-前端与AI技术周报 TypeScript 7.0 正式发布 2026-07-12-前端与AI技术周报 2026-07-05-前端与AI技术周报 MCP 还是 CLI + Skill? 2026-06-28-前端与AI技术周报 2026-06-22-AI 产品周报 2026-06-22-前端技术周报 2026-06-14-AI 产品周报 2026-06-14-前端技术周报 2026-06-08-AI 产品周报 2026-06-07-前端技术周报 2026-05-31-AI 产品周报 2026-05-31-前端技术周报 2026-05-24-AI 产品周报 2026-05-24-前端技术周报 AI Review pnpm 的 catalogs 功能 使用 SSE 与 Streamdown 实现 Markdown 流式渲染 JavaScript Intl 对象全面指南 POML 一种管理 Prompt 的工具 如何使用 Translator Web API eslint 支持多线程并发 Lint 下一代前端工具链对比 如何开发自己的一个 shadcn 组件 shadcn-ui实现原理 TypeScript全局类型定义的方式 IntersectionObserver API 用法 web图像格式对比(三) web图像格式对比(四) web图像格式对比(一) web图像格式对比(二) 混合内容请求限制
在 electron 中使用 chrome-devtools-mcp
Oxygen · 2026-01-08 · via icodex | 前端技术博客 | 专注 React、TypeScript、AI 与性能优化 Blog

本文介绍在开发 electron 应用时如何使用 chrome-devtools-mcp,比较简单。

安装 chrome-devtools-mcp 比较简单,找到 GitHub 仓库,在 README 中能找到各种工具的安装方式,这里就不介绍了。

以 vscode 为例,推荐在项目目录下单独配置,避免多个项目之间配置无法共享。chrome-devtools-mcp 的基本配置如下:

{
"servers": {
"chrome-devtools-mcp": {
"type": "stdio",
"command": "npx",
"args": ["-y", "chrome-devtools-mcp@latest"]
}
}
}

参考 chrome-devtools-mcp 中的文档 - Manual connection using port forwarding,也就是通过 --browser-url 选项连接到正在运行的 Chrome 实例。适用于在沙箱环境中运行 MCP 服务器,且不允许启动新的 Chrome 实例。那 electron 就符合这种条件。

首先,我们需要在 chrome-devtools-mcp 配置中新增--browser-url 配置项,端口号随意

{
"servers": {
"chrome-devtools-mcp": {
"type": "stdio",
"command": "npx",
"args": [
"-y",
"chrome-devtools-mcp@latest",
// 加上这一个参数,端口号随意
"--browser-url=http://127.0.0.1:9222"
]
}
}
}

然后在 electron 应用中增加以下开发环境配置来启动开发环境调试端口,端口号必须与你在 mcp 中browser-url 指定的端口号相同。

import isDev from "electron-is-dev";

if (isDev) {
// 启用远程调试端口
app.commandLine.appendSwitch("remote-debugging-port", "9222");
// 可选,开发环境数据隔离
app.setPath("userData", join(app.getPath("appData"), `electron-mcp-dev`));
}

就这么简单两步,接下来就能使用 chrome-devtools-mcp 执行你想做的任何自动测试了。