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

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
雷峰网
雷峰网
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Spread Privacy
Spread Privacy
H
Hacker News: Front Page
PCI Perspectives
PCI Perspectives
Webroot Blog
Webroot Blog
罗磊的独立博客
H
Heimdal Security Blog
TaoSecurity Blog
TaoSecurity Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
大猫的无限游戏
大猫的无限游戏
月光博客
月光博客
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Google Online Security Blog
Google Online Security Blog
Last Week in AI
Last Week in AI
美团技术团队
Help Net Security
Help Net Security
The Hacker News
The Hacker News
C
Cisco Blogs
T
The Blog of Author Tim Ferriss
J
Java Code Geeks
The Register - Security
The Register - Security
IT之家
IT之家
WordPress大学
WordPress大学
Jina AI
Jina AI
Recent Commits to openclaw:main
Recent Commits to openclaw:main
H
Help Net Security
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
T
Threat Research - Cisco Blogs
P
Proofpoint News Feed
NISL@THU
NISL@THU
爱范儿
爱范儿
The GitHub Blog
The GitHub Blog
Scott Helme
Scott Helme
V
Vulnerabilities – Threatpost
B
Blog
T
Tenable Blog
博客园 - 三生石上(FineUI控件)
T
The Exploit Database - CXSecurity.com
S
Security Affairs
小众软件
小众软件
Hacker News: Ask HN
Hacker News: Ask HN
Security Latest
Security Latest
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
W
WeLiveSecurity
A
Arctic Wolf
L
LINUX DO - 热门话题
Google DeepMind News
Google DeepMind News
M
MIT News - Artificial intelligence

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 执行你想做的任何自动测试了。