devtools
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseChrome DevTools MCP Setup
Chrome DevTools MCP 设置
Overview
概述
This skill automates the setup and launch of Chrome with remote debugging for use with the chrome-devtools-mcp server. It handles environment detection, Chrome installation verification, MCP configuration, and browser launch across Windows, Linux, and WSL2.
GitHub Repository: https://github.com/ChromeDevTools/chrome-devtools-mcp
本Skill可自动完成Chrome的设置与启动,并开启远程调试功能,以供chrome-devtools-mcp服务器使用。它支持在Windows、Linux和WSL2环境下进行环境检测、Chrome安装验证、MCP配置以及浏览器启动。
Why Give Claude Browser Access?
为何要让Claude访问浏览器?
Without browser access, Claude is "coding blindfolded" - making changes without seeing the results. The Chrome DevTools MCP server provides 26 specialised tools that give Claude eyes into your running application:
| Category | Capabilities |
|---|---|
| Visual Inspection | Take screenshots, capture DOM snapshots, see rendered output |
| Console & Logging | Read console messages, catch JavaScript errors, debug issues |
| Network Analysis | Inspect API requests/responses, analyse headers, debug fetch calls |
| Performance | Record traces, measure Core Web Vitals (LCP, CLS, TBT), identify bottlenecks |
| User Simulation | Click elements, fill forms, drag-and-drop, handle dialogs |
| Device Emulation | Simulate mobile viewports, throttle CPU/network, test responsive design |
This enables Claude to:
- Verify changes visually instead of guessing if CSS/layout is correct
- Debug runtime errors by reading actual console output
- Test user flows by simulating clicks and form submissions
- Identify performance issues with real Core Web Vitals data
- Catch regressions by comparing screenshots before/after changes
如果没有浏览器访问权限,Claude就像“蒙眼编码”——无法看到修改结果就进行更改。Chrome DevTools MCP服务器提供了26种专用工具,让Claude能够“看到”你正在运行的应用:
| 类别 | 功能 |
|---|---|
| 可视化检查 | 截图、捕获DOM快照、查看渲染输出 |
| 控制台与日志 | 读取控制台消息、捕获JavaScript错误、调试问题 |
| 网络分析 | 查看API请求/响应、分析请求头、调试fetch调用 |
| 性能分析 | 录制性能轨迹、测量Core Web Vitals(LCP、CLS、TBT)、识别性能瓶颈 |
| 用户模拟 | 点击元素、填写表单、拖放操作、处理对话框 |
| 设备模拟 | 模拟移动视口、限制CPU/网络速度、测试响应式设计 |
这让Claude能够:
- 可视化验证修改,无需猜测CSS/布局是否正确
- 通过读取实际控制台输出来调试运行时错误
- 通过模拟点击和表单提交来测试用户流程
- 借助真实的Core Web Vitals数据识别性能问题
- 通过对比修改前后的截图来捕获回归问题
Quick Start Workflow
快速开始流程
Execute these steps in order:
请按以下顺序执行步骤:
Step 1: Detect Environment
步骤1:检测环境
Run the environment detection script to determine the platform:
bash
bash scripts/detect_environment.shThe script returns one of: , , or
windowslinuxwsl2运行环境检测脚本以确定当前平台:
bash
bash scripts/detect_environment.sh该脚本会返回以下值之一:、或
windowslinuxwsl2Step 2: Verify Chrome Installation
步骤2:验证Chrome安装
Run the Chrome check script with the detected environment:
bash
bash scripts/check_chrome.sh <environment>The script outputs or . If Chrome is not installed, the script provides detailed installation instructions. See the Chrome Installation section below for manual installation options.
status:installedstatus:not_installedIMPORTANT: Do not proceed to later steps until Chrome is installed and verified.
使用检测到的环境运行Chrome检查脚本:
bash
bash scripts/check_chrome.sh <environment>该脚本会输出或。如果未安装Chrome,脚本会提供详细的安装说明。如需手动安装选项,请查看下方的Chrome安装章节。
status:installedstatus:not_installed重要提示: 在Chrome安装并验证完成前,请不要进行后续步骤。
Step 3: Check MCP Server Status
步骤3:检查MCP服务器状态
Verify if chrome-devtools-mcp is configured:
bash
claude mcp list | grep -i chromeIf not installed, install with:
bash
claude mcp add chrome-devtools -- npx chrome-devtools-mcp@latest --browserUrl http://127.0.0.1:9222验证chrome-devtools-mcp是否已配置:
bash
claude mcp list | grep -i chrome如果未安装,请使用以下命令安装:
bash
claude mcp add chrome-devtools -- npx chrome-devtools-mcp@latest --browserUrl http://127.0.0.1:9222Step 4: Detect Running Dev Server
步骤4:检测运行中的开发服务器
Check for running dev servers on common ports:
bash
bash scripts/detect_dev_server.shThis checks ports 5173, 5174, 5175, 3000, 3001, 8080, and 8000.
If no dev server is running and one is needed, offer to start it:
- For Vite projects:
npm run dev - For Next.js: or
npm run devnpx next dev - For React CRA:
npm start
检查常用端口上是否有运行中的开发服务器:
bash
bash scripts/detect_dev_server.sh该脚本会检查端口5173、5174、5175、3000、3001、8080和8000。
如果没有运行中的开发服务器且需要启动,请使用以下命令:
- 对于Vite项目:
npm run dev - 对于Next.js项目:或
npm run devnpx next dev - 对于React CRA项目:
npm start
Step 5: Launch Chrome with Debugging
步骤5:启动带调试功能的Chrome
Launch Chrome with remote debugging enabled:
bash
bash scripts/launch_chrome.sh <environment> <url> [headed]Arguments:
- :
<environment>,windows, orlinuxwsl2 - : Target URL (e.g.,
<url>)http://localhost:5173 - : Optional - pass
[headed]for visible browser, omit for headless (default)headed
Examples:
bash
undefined启动Chrome并启用远程调试:
bash
bash scripts/launch_chrome.sh <environment> <url> [headed]参数说明:
- :
<environment>、windows或linuxwsl2 - :目标URL(例如:
<url>)http://localhost:5173 - :可选参数 - 传入
[headed]会启动可见的浏览器窗口,省略则以无头模式启动(默认)headed
示例:
bash
undefinedHeadless (default)
无头模式(默认)
bash scripts/launch_chrome.sh wsl2 http://localhost:5173
bash scripts/launch_chrome.sh wsl2 http://localhost:5173
Headed (visible browser)
有头模式(可见浏览器)
bash scripts/launch_chrome.sh wsl2 http://localhost:5173 headed
undefinedbash scripts/launch_chrome.sh wsl2 http://localhost:5173 headed
undefinedPlatform-Specific Commands
平台专属命令
WSL2 / Linux
WSL2 / Linux
bash
undefinedbash
undefinedHeadless
无头模式
google-chrome --headless --remote-debugging-port=9222 --no-first-run --user-data-dir=/tmp/chrome-mcp http://localhost:5173 &
google-chrome --headless --remote-debugging-port=9222 --no-first-run --user-data-dir=/tmp/chrome-mcp http://localhost:5173 &
Headed
有头模式
google-chrome --remote-debugging-port=9222 --no-first-run --user-data-dir=/tmp/chrome-mcp http://localhost:5173 &
undefinedgoogle-chrome --remote-debugging-port=9222 --no-first-run --user-data-dir=/tmp/chrome-mcp http://localhost:5173 &
undefinedWindows (CMD/PowerShell)
Windows(CMD/PowerShell)
cmd
REM Headless
start chrome.exe --headless --remote-debugging-port=9222 --no-first-run --user-data-dir=%TEMP%\chrome-mcp http://localhost:5173
REM Headed
start chrome.exe --remote-debugging-port=9222 --no-first-run --user-data-dir=%TEMP%\chrome-mcp http://localhost:5173cmd
REM 无头模式
start chrome.exe --headless --remote-debugging-port=9222 --no-first-run --user-data-dir=%TEMP%\chrome-mcp http://localhost:5173
REM 有头模式
start chrome.exe --remote-debugging-port=9222 --no-first-run --user-data-dir=%TEMP%\chrome-mcp http://localhost:5173Chrome Installation
Chrome安装
If Chrome is not detected, install it using one of these methods:
如果未检测到Chrome,请使用以下方法之一进行安装:
Linux / WSL2
Linux / WSL2
Option 1: Direct download (recommended)
bash
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo apt install -y ./google-chrome-stable_current_amd64.debOption 2: Add Google's repository
bash
undefined选项1:直接下载(推荐)
bash
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo apt install -y ./google-chrome-stable_current_amd64.deb选项2:添加Google软件源
bash
undefinedAdd signing key
添加签名密钥
wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo gpg --dearmor -o /usr/share/keyrings/google-chrome.gpg
wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo gpg --dearmor -o /usr/share/keyrings/google-chrome.gpg
Add repository
添加软件源
echo 'deb [arch=amd64 signed-by=/usr/share/keyrings/google-chrome.gpg] http://dl.google.com/linux/chrome/deb/ stable main' | sudo tee /etc/apt/sources.list.d/google-chrome.list
echo 'deb [arch=amd64 signed-by=/usr/share/keyrings/google-chrome.gpg] http://dl.google.com/linux/chrome/deb/ stable main' | sudo tee /etc/apt/sources.list.d/google-chrome.list
Install
安装
sudo apt update
sudo apt install -y google-chrome-stable
**Option 3: Chromium (open-source alternative)**
```bash
sudo apt update
sudo apt install -y chromium-browsersudo apt update
sudo apt install -y google-chrome-stable
**选项3:Chromium(开源替代方案)**
```bash
sudo apt update
sudo apt install -y chromium-browserWindows
Windows
Option 1: Download from Google
Visit https://www.google.com/chrome/ and run the installer.
Option 2: Using winget
powershell
winget install Google.ChromeOption 3: Using Chocolatey
powershell
choco install googlechromeOption 4: PowerShell direct download
powershell
$installer = "$env:TEMP\chrome_installer.exe"
Invoke-WebRequest -Uri "https://dl.google.com/chrome/install/latest/chrome_installer.exe" -OutFile $installer
Start-Process -FilePath $installer -Args "/silent /install" -Wait
Remove-Item $installer选项1:从Google官网下载
访问https://www.google.com/chrome/ 并运行安装程序。
选项2:使用winget
powershell
winget install Google.Chrome选项3:使用Chocolatey
powershell
choco install googlechrome选项4:通过PowerShell直接下载
powershell
$installer = "$env:TEMP\chrome_installer.exe"
Invoke-WebRequest -Uri "https://dl.google.com/chrome/install/latest/chrome_installer.exe" -OutFile $installer
Start-Process -FilePath $installer -Args "/silent /install" -Wait
Remove-Item $installerVerify Installation
验证安装
After installation, verify with:
bash
bash scripts/check_chrome.sh <environment>安装完成后,使用以下命令验证:
bash
bash scripts/check_chrome.sh <environment>MCP Configuration
MCP配置
Quick Install
快速安装
bash
claude mcp add chrome-devtools -- npx chrome-devtools-mcp@latest --browserUrl http://127.0.0.1:9222bash
claude mcp add chrome-devtools -- npx chrome-devtools-mcp@latest --browserUrl http://127.0.0.1:9222Configuration Reference
配置参考
All flags can be passed via the array in :
args.mcp.json| Flag | Description | Default |
|---|---|---|
| Connect to running Chrome (e.g., | - |
| Auto-connect to Chrome 145+ with remote debugging enabled | |
| Run in headless (no UI) mode | |
| Use temporary user-data-dir, auto-cleaned on close | |
| Chrome channel: | |
| Initial viewport size (e.g., | - |
| Path to custom Chrome executable | - |
| Custom user data directory | |
| WebSocket endpoint (alternative to | - |
| Custom WebSocket headers as JSON (use with | - |
| Proxy server for Chrome | - |
| Ignore self-signed/expired certificate errors | |
| Additional Chrome launch arguments (array) | - |
| Debug log file path (set | - |
| Include emulation tools | |
| Include performance tools | |
| Include network tools | |
所有参数均可通过中的数组传递:
.mcp.jsonargs| 参数 | 说明 | 默认值 |
|---|---|---|
| 连接到运行中的Chrome(例如: | 无 |
| 自动连接到启用了远程调试的Chrome 145及以上版本 | |
| 以无头模式(无界面)运行 | |
| 使用临时用户数据目录,关闭时自动清理 | |
| Chrome渠道: | |
| 初始视口尺寸(例如: | 无 |
| 自定义Chrome可执行文件路径 | 无 |
| 自定义用户数据目录 | |
| WebSocket端点( | 无 |
| 自定义WebSocket头(JSON格式,需与 | 无 |
| Chrome使用的代理服务器 | 无 |
| 忽略自签名/过期证书错误 | |
| 额外的Chrome启动参数(数组形式) | 无 |
| 调试日志文件路径(设置 | 无 |
| 启用模拟工具 | |
| 启用性能工具 | |
| 启用网络工具 | |
Basic Configuration
基础配置
json
{
"mcpServers": {
"chrome-devtools": {
"command": "npx",
"args": [
"chrome-devtools-mcp@latest",
"--browserUrl",
"http://127.0.0.1:9222"
]
}
}
}json
{
"mcpServers": {
"chrome-devtools": {
"command": "npx",
"args": [
"chrome-devtools-mcp@latest",
"--browserUrl",
"http://127.0.0.1:9222"
]
}
}
}Headless with Isolated Profile
无头模式与独立配置文件
Best for CI/CD or automated testing - uses a temporary profile that's cleaned up automatically:
json
{
"mcpServers": {
"chrome-devtools": {
"command": "npx",
"args": [
"chrome-devtools-mcp@latest",
"--headless",
"--isolated"
]
}
}
}适用于CI/CD或自动化测试 - 使用临时配置文件,关闭浏览器时会自动清理:
json
{
"mcpServers": {
"chrome-devtools": {
"command": "npx",
"args": [
"chrome-devtools-mcp@latest",
"--headless",
"--isolated"
]
}
}
}Custom Viewport for Mobile Testing
移动端测试自定义视口
json
{
"mcpServers": {
"chrome-devtools": {
"command": "npx",
"args": [
"chrome-devtools-mcp@latest",
"--browserUrl=http://127.0.0.1:9222",
"--viewport=390x844"
]
}
}
}json
{
"mcpServers": {
"chrome-devtools": {
"command": "npx",
"args": [
"chrome-devtools-mcp@latest",
"--browserUrl=http://127.0.0.1:9222",
"--viewport=390x844"
]
}
}
}Using Chrome Canary/Beta
使用Chrome Canary/Beta版本
json
{
"mcpServers": {
"chrome-devtools": {
"command": "npx",
"args": [
"chrome-devtools-mcp@latest",
"--channel=canary",
"--headless",
"--isolated"
]
}
}
}json
{
"mcpServers": {
"chrome-devtools": {
"command": "npx",
"args": [
"chrome-devtools-mcp@latest",
"--channel=canary",
"--headless",
"--isolated"
]
}
}
}With Debug Logging
启用调试日志
json
{
"mcpServers": {
"chrome-devtools": {
"command": "npx",
"args": [
"chrome-devtools-mcp@latest",
"--browserUrl=http://127.0.0.1:9222",
"--logFile=/tmp/chrome-devtools-mcp.log"
],
"env": {
"DEBUG": "*"
}
}
}
}json
{
"mcpServers": {
"chrome-devtools": {
"command": "npx",
"args": [
"chrome-devtools-mcp@latest",
"--browserUrl=http://127.0.0.1:9222",
"--logFile=/tmp/chrome-devtools-mcp.log"
],
"env": {
"DEBUG": "*"
}
}
}
}WebSocket Connection with Auth Headers
带认证头的WebSocket连接
For connecting to remote Chrome instances with authentication:
json
{
"mcpServers": {
"chrome-devtools": {
"command": "npx",
"args": [
"chrome-devtools-mcp@latest",
"--wsEndpoint=ws://127.0.0.1:9222/devtools/browser/<id>",
"--wsHeaders={\"Authorization\":\"Bearer YOUR_TOKEN\"}"
]
}
}
}To get the WebSocket endpoint, visit and look for .
http://127.0.0.1:9222/json/versionwebSocketDebuggerUrl用于连接需要认证的远程Chrome实例:
json
{
"mcpServers": {
"chrome-devtools": {
"command": "npx",
"args": [
"chrome-devtools-mcp@latest",
"--wsEndpoint=ws://127.0.0.1:9222/devtools/browser/<id>",
"--wsHeaders={\"Authorization\":\"Bearer YOUR_TOKEN\"}"
]
}
}
}如需获取WebSocket端点,请访问并查找字段。
http://127.0.0.1:9222/json/versionwebSocketDebuggerUrlConnection Methods
连接方式
Method 1: Manual Connection (Recommended)
方式1:手动连接(推荐)
Start Chrome yourself with remote debugging, then connect via . This is the approach used in the Quick Start Workflow above.
--browserUrlWhen to use:
- Running Claude in a sandboxed environment
- Need full control over Chrome launch options
- Working with self-signed certificates
自行启动带远程调试的Chrome,然后通过连接。这是快速开始流程中使用的方法。
--browserUrl适用场景:
- 在沙箱环境中运行Claude
- 需要完全控制Chrome的启动选项
- 使用自签名证书的场景
Method 2: Auto-Connect (Chrome 145+)
方式2:自动连接(Chrome 145及以上版本)
Let chrome-devtools-mcp automatically connect to a running Chrome instance.
Step 1: Enable remote debugging in Chrome:
- Navigate to
chrome://inspect/#remote-debugging - Follow the dialog to allow debugging connections
Step 2: Configure MCP with :
--autoConnectjson
{
"mcpServers": {
"chrome-devtools": {
"command": "npx",
"args": ["chrome-devtools-mcp@latest", "--autoConnect"]
}
}
}When to use:
- Sharing state between manual testing and Claude-driven testing
- Avoiding WebDriver sign-in blocks (some sites block automated browsers)
- Want Chrome to prompt for permission before Claude connects
让chrome-devtools-mcp自动连接到运行中的Chrome实例。
步骤1: 在Chrome中启用远程调试:
- 访问
chrome://inspect/#remote-debugging - 按照提示对话框允许调试连接
步骤2: 配置MCP并启用:
--autoConnectjson
{
"mcpServers": {
"chrome-devtools": {
"command": "npx",
"args": ["chrome-devtools-mcp@latest", "--autoConnect"]
}
}
}适用场景:
- 在手动测试与Claude驱动的测试之间共享状态
- 避免WebDriver登录拦截(部分网站会拦截自动化浏览器)
- 希望Claude连接前Chrome会提示获取权限
Method 3: Let MCP Launch Chrome
方式3:让MCP启动Chrome
If you omit and , the MCP server will launch its own Chrome instance.
--browserUrl--autoConnectjson
{
"mcpServers": {
"chrome-devtools": {
"command": "npx",
"args": ["chrome-devtools-mcp@latest", "--headless", "--isolated"]
}
}
}When to use:
- Fully automated workflows
- No need to maintain browser state
- CI/CD pipelines
如果省略和,MCP服务器会自行启动Chrome实例。
--browserUrl--autoConnectjson
{
"mcpServers": {
"chrome-devtools": {
"command": "npx",
"args": ["chrome-devtools-mcp@latest", "--headless", "--isolated"]
}
}
}适用场景:
- 全自动化工作流
- 无需保留浏览器状态
- CI/CD流水线
User Data Directory
用户数据目录
By default, chrome-devtools-mcp uses a persistent profile at:
- Linux/macOS:
$HOME/.cache/chrome-devtools-mcp/chrome-profile-$CHANNEL - Windows:
%HOMEPATH%/.cache/chrome-devtools-mcp/chrome-profile-$CHANNEL
This profile is shared across all MCP sessions, preserving cookies, local storage, and login state.
Use for a fresh, temporary profile that's automatically cleaned up when the browser closes.
--isolated默认情况下,chrome-devtools-mcp会使用以下路径的持久化配置文件:
- Linux/macOS:
$HOME/.cache/chrome-devtools-mcp/chrome-profile-$CHANNEL - Windows:
%HOMEPATH%/.cache/chrome-devtools-mcp/chrome-profile-$CHANNEL
该配置文件会在所有MCP会话中共享,保留Cookie、本地存储和登录状态。
使用参数可创建全新的临时配置文件,浏览器关闭时会自动清理。
--isolatedTroubleshooting
故障排查
For detailed troubleshooting steps, read .
references/troubleshooting.md如需详细的故障排查步骤,请查看。
references/troubleshooting.mdQuick Checks
快速检查
-
Test MCP server runs:bash
npx chrome-devtools-mcp@latest --help -
Verify Chrome is listening:bash
curl -s http://127.0.0.1:9222/json/version -
Check for existing Chrome processes:bash
# Linux/WSL2 pgrep -a chrome # Windows tasklist | findstr chrome
-
测试MCP服务器能否运行:bash
npx chrome-devtools-mcp@latest --help -
验证Chrome是否在监听端口:bash
curl -s http://127.0.0.1:9222/json/version -
检查是否有Chrome进程在运行:bash
# Linux/WSL2 pgrep -a chrome # Windows tasklist | findstr chrome
Common Issues
常见问题
| Issue | Solution |
|---|---|
| "Target closed" error | Close all Chrome instances, restart with debugging |
| Module not found | Clear npm cache: |
| Connection refused | Ensure Chrome launched with |
| Port already in use | Kill existing Chrome or use different port |
| Chrome won't start in sandbox | Use |
| WebDriver sign-in blocked | Use |
| VM-to-host connection fails | See |
| 问题 | 解决方案 |
|---|---|
| "Target closed"错误 | 关闭所有Chrome实例,重新启动并开启调试 |
| 模块未找到 | 清理npm缓存: |
| 连接被拒绝 | 确保Chrome启动时添加了 |
| 端口已被占用 | 终止现有Chrome进程或使用其他端口 |
| Chrome无法在沙箱中启动 | 使用 |
| WebDriver登录被拦截 | 使用 |
| 虚拟机到主机的连接失败 | 查看 |
Known Limitations
已知限制
Operating System Sandboxes
操作系统沙箱
Some MCP clients sandbox the server using macOS Seatbelt or Linux containers. In sandboxed environments, chrome-devtools-mcp cannot start Chrome (which requires its own sandbox permissions).
Workarounds:
- Disable sandboxing for chrome-devtools-mcp in your MCP client
- Use to connect to a Chrome instance started outside the sandbox
--browserUrl
部分MCP客户端会使用macOS Seatbelt或Linux容器对服务器进行沙箱隔离。在沙箱环境中,chrome-devtools-mcp无法启动Chrome(因为Chrome需要自身的沙箱权限)。
解决方法:
- 在你的MCP客户端中禁用chrome-devtools-mcp的沙箱隔离
- 使用连接到在沙箱外启动的Chrome实例
--browserUrl
Security Considerations
安全注意事项
The remote debugging port exposes your browser to any application on your machine. When debugging is enabled:
- Avoid browsing sensitive sites (banking, email with sensitive data)
- Use for a separate profile
--isolated - Close Chrome when done debugging
远程调试端口会让你的浏览器对本地所有应用开放。启用调试时:
- 避免访问敏感网站(如银行、包含敏感数据的邮箱)
- 使用参数创建独立配置文件
--isolated - 调试完成后关闭Chrome
Verification
验证
After setup, verify the connection works:
- Chrome should be running with remote debugging
- MCP server should connect to
http://127.0.0.1:9222 - Test with tool
mcp__chrome-devtools__list_pages
设置完成后,验证连接是否正常:
- Chrome应已启动并开启远程调试
- MCP服务器应已连接到
http://127.0.0.1:9222 - 使用工具进行测试
mcp__chrome-devtools__list_pages