chrome-devtools
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseChrome DevTools Agent Skill
Chrome DevTools Agent Skill
Browser automation via executable Puppeteer scripts. All scripts output JSON for easy parsing.
通过可执行的Puppeteer脚本实现浏览器自动化。所有脚本均输出JSON格式,便于解析。
Quick Start
快速开始
CRITICAL: Always check before running scripts.
pwd重要提示:运行脚本前务必检查。
pwdInstallation
安装
Step 1: Install System Dependencies (Linux/WSL only)
步骤1:安装系统依赖(仅Linux/WSL)
On Linux/WSL, Chrome requires system libraries. Install them first:
bash
pwd # Should show current working directory
cd .claude/skills/chrome-devtools/scripts
./install-deps.sh # Auto-detects OS and installs required libsSupports: Ubuntu, Debian, Fedora, RHEL, CentOS, Arch, Manjaro
macOS/Windows: Skip this step (dependencies bundled with Chrome)
在Linux/WSL系统中,Chrome需要依赖系统库。请先安装这些库:
bash
pwd # 显示当前工作目录
cd .claude/skills/chrome-devtools/scripts
./install-deps.sh # 自动检测操作系统并安装所需库支持:Ubuntu、Debian、Fedora、RHEL、CentOS、Arch、Manjaro
macOS/Windows用户:跳过此步骤(Chrome已捆绑依赖)
Step 2: Install Node Dependencies
步骤2:安装Node依赖
bash
undefinedbash
undefinedPreferred: Using bun (faster)
推荐方式:使用bun(速度更快)
bun install # Installs puppeteer, debug, yargs
bun install # 安装puppeteer、debug、yargs
Alternative: Using npm
替代方式:使用npm
npm install
undefinednpm install
undefinedStep 3: Install ImageMagick (Optional, Recommended)
步骤3:安装ImageMagick(可选,推荐)
ImageMagick enables automatic screenshot compression to keep files under 5MB:
macOS:
bash
brew install imagemagickUbuntu/Debian/WSL:
bash
sudo apt-get install imagemagickVerify:
bash
magick -version # or: convert -versionWithout ImageMagick, screenshots >5MB will not be compressed (may fail to load in Gemini/Claude).
ImageMagick可自动压缩截图,确保文件大小不超过5MB:
macOS:
bash
brew install imagemagickUbuntu/Debian/WSL:
bash
sudo apt-get install imagemagick验证:
bash
magick -version # 或:convert -version如果未安装ImageMagick,大于5MB的截图将不会被压缩(可能无法在Gemini/Claude中加载)。
Test
测试
bash
bun navigate.js --url https://example.combash
bun navigate.js --url https://example.comOutput: {"success": true, "url": "https://example.com", "title": "Example Domain"}
输出:{"success": true, "url": "https://example.com", "title": "Example Domain"}
undefinedundefinedAvailable Scripts
可用脚本
All scripts are in
.claude/skills/chrome-devtools/scripts/CRITICAL: Always check before running scripts.
pwd所有脚本位于目录下
.claude/skills/chrome-devtools/scripts/重要提示:运行脚本前务必检查。
pwdScript Usage
脚本使用说明
./scripts/README.md
./scripts/README.md
Core Automation
核心自动化脚本
- - Navigate to URLs
navigate.js - - Capture screenshots (full page or element)
screenshot.js - - Click elements
click.js - - Fill form fields
fill.js - - Execute JavaScript in page context
evaluate.js
- - 导航至指定URL
navigate.js - - 捕获截图(整页或指定元素)
screenshot.js - - 点击元素
click.js - - 填充表单字段
fill.js - - 在页面上下文执行JavaScript
evaluate.js
Analysis & Monitoring
分析与监控脚本
- - Extract interactive elements with metadata
snapshot.js - - Monitor console messages/errors
console.js - - Track HTTP requests/responses
network.js - - Measure Core Web Vitals + record traces
performance.js
- - 提取带元数据的交互元素
snapshot.js - - 监控控制台消息/错误
console.js - - 追踪HTTP请求/响应
network.js - - 测量核心Web指标并记录追踪数据
performance.js
Usage Patterns
使用模式
Single Command
单命令执行
bash
pwd # Should show current working directory
cd .claude/skills/chrome-devtools/scripts
bun screenshot.js --url https://example.com --output ./docs/screenshots/page.pngImportant: Always save screenshots to directory.
./docs/screenshotsbash
pwd # 应显示当前工作目录
cd .claude/skills/chrome-devtools/scripts
bun screenshot.js --url https://example.com --output ./docs/screenshots/page.png注意:请始终将截图保存至目录。
./docs/screenshotsAutomatic Image Compression
自动图片压缩
Screenshots are automatically compressed if they exceed 5MB to ensure compatibility with Gemini API and Claude Code (which have 5MB limits). This uses ImageMagick internally:
bash
undefined如果截图超过5MB,系统会自动压缩以确保兼容Gemini API和Claude Code(二者均有5MB大小限制)。此功能内部使用ImageMagick:
bash
undefinedDefault: auto-compress if >5MB
默认:超过5MB时自动压缩
bun screenshot.js --url https://example.com --output page.png
bun screenshot.js --url https://example.com --output page.png
Custom size threshold (e.g., 3MB)
自定义大小阈值(例如3MB)
bun screenshot.js --url https://example.com --output page.png --max-size 3
bun screenshot.js --url https://example.com --output page.png --max-size 3
Disable compression
禁用压缩
bun screenshot.js --url https://example.com --output page.png --no-compress
**Compression behavior:**
- PNG: Resizes to 90% + quality 85 (or 75% + quality 70 if still too large)
- JPEG: Quality 80 + progressive encoding (or quality 60 if still too large)
- Other formats: Converted to JPEG with compression
- Requires ImageMagick installed (see imagemagick skill)
**Output includes compression info:**
```json
{
"success": true,
"output": "/path/to/page.png",
"compressed": true,
"originalSize": 8388608,
"size": 3145728,
"compressionRatio": "62.50%",
"url": "https://example.com"
}bun screenshot.js --url https://example.com --output page.png --no-compress
**压缩规则:**
- PNG格式:先调整至原大小的90%并设置质量为85(如果仍过大则调整至75%并设置质量为70)
- JPEG格式:设置质量为80并启用渐进式编码(如果仍过大则设置质量为60)
- 其他格式:转换为JPEG格式并进行压缩
- 需要提前安装ImageMagick(详见ImageMagick技能文档)
**输出包含压缩信息:**
```json
{
"success": true,
"output": "/path/to/page.png",
"compressed": true,
"originalSize": 8388608,
"size": 3145728,
"compressionRatio": "62.50%",
"url": "https://example.com"
}Chain Commands (reuse browser)
链式命令(复用浏览器)
bash
undefinedbash
undefinedKeep browser open with --close false
保持浏览器打开:--close false
bun navigate.js --url https://example.com/login --close false
bun fill.js --selector "#email" --value "user@example.com" --close false
bun fill.js --selector "#password" --value "secret" --close false
bun click.js --selector "button[type=submit]"
undefinedbun navigate.js --url https://example.com/login --close false
bun fill.js --selector "#email" --value "user@example.com" --close false
bun fill.js --selector "#password" --value "secret" --close false
bun click.js --selector "button[type=submit]"
undefinedParse JSON Output
解析JSON输出
bash
undefinedbash
undefinedExtract specific fields with jq
使用jq提取特定字段
bun performance.js --url https://example.com | jq '.vitals.LCP'
bun performance.js --url https://example.com | jq '.vitals.LCP'
Save to file
保存至文件
bun network.js --url https://example.com --output /tmp/requests.json
undefinedbun network.js --url https://example.com --output /tmp/requests.json
undefinedExecution Protocol
执行规范
Working Directory Verification
工作目录验证
BEFORE executing any script:
- Check current working directory with
pwd - Verify in directory
.claude/skills/chrome-devtools/scripts/ - If wrong directory, to correct location
cd - Use absolute paths for all output files
Example:
bash
pwd # Should show: .../chrome-devtools/scripts执行任何脚本之前:
- 使用检查当前工作目录
pwd - 确认位于目录下
.claude/skills/chrome-devtools/scripts/ - 如果目录错误,使用切换至正确位置
cd - 所有输出文件使用绝对路径
示例:
bash
pwd # 应显示:.../chrome-devtools/scriptsIf wrong:
如果目录错误:
cd .claude/skills/chrome-devtools/scripts
undefinedcd .claude/skills/chrome-devtools/scripts
undefinedOutput Validation
输出验证
AFTER screenshot/capture operations:
- Verify file created with
ls -lh <output-path> - Read screenshot using Read tool to confirm content
- Check JSON output for success:true
- Report file size and compression status
Example:
bash
bun screenshot.js --url https://example.com --output ./docs/screenshots/page.png
ls -lh ./docs/screenshots/page.png # Verify file exists截图/捕获操作完成后:
- 使用验证文件已创建
ls -lh <output-path> - 使用读取工具查看截图内容以确认有效性
- 检查JSON输出中的字段
success:true - 报告文件大小和压缩状态
示例:
bash
bun screenshot.js --url https://example.com --output ./docs/screenshots/page.png
ls -lh ./docs/screenshots/page.png # 验证文件存在Then use Read tool to visually inspect
然后使用读取工具进行视觉检查
5. Restart working directory to the project root.
5. 将工作目录重置为项目根目录。Error Recovery
错误恢复
If script fails:
- Check error message for selector issues
- Use snapshot.js to discover correct selectors
- Try XPath selector if CSS selector fails
- Verify element is visible and interactive
Example:
bash
undefined如果脚本执行失败:
- 检查错误信息,确认是否为选择器问题
- 使用查找正确的选择器
snapshot.js - 如果CSS选择器失败,尝试使用XPath选择器
- 验证元素是否可见且可交互
示例:
bash
undefinedCSS selector fails
CSS选择器执行失败
bun click.js --url https://example.com --selector ".btn-submit"
bun click.js --url https://example.com --selector ".btn-submit"
Error: waiting for selector ".btn-submit" failed
错误信息:waiting for selector ".btn-submit" failed
Discover correct selector
查找正确的选择器
bun snapshot.js --url https://example.com | jq '.elements[] | select(.tagName=="BUTTON")'
bun snapshot.js --url https://example.com | jq '.elements[] | select(.tagName=="BUTTON")'
Try XPath
尝试XPath选择器
bun click.js --url https://example.com --selector "//button[contains(text(),'Submit')]"
undefinedbun click.js --url https://example.com --selector "//button[contains(text(),'Submit')]"
undefinedCommon Options
通用选项
All scripts support:
- - Show browser window (default: true)
--headless false - - Keep browser open after script
--close false - - Timeout in milliseconds (default: 30000)
--timeout 30000 - - Show script-specific help
--help
所有脚本均支持:
- - 显示浏览器窗口(默认值:true)
--headless false - - 脚本执行后保持浏览器打开
--close false - - 超时时间(毫秒,默认值:30000)
--timeout 30000 - - 显示脚本专属帮助信息
--help
Troubleshooting
故障排查
Browser fails to launch (Linux):
bash
./install-deps.sh # Install missing system librariesLarge screenshots:
- Enable ImageMagick for automatic compression
- Use to set custom threshold
--max-size - Or capture specific element instead of full page
Element not found:
- Use first to discover selectors
snapshot.js - Check if element is dynamically loaded (wait longer)
- Try XPath if CSS fails
Script not found:
- Verify you're in the correct directory
- Check script name spelling
- Use absolute path:
bun /path/to/scripts/navigate.js
浏览器启动失败(Linux系统):
bash
./install-deps.sh # 安装缺失的系统库大尺寸截图问题:
- 安装ImageMagick以启用自动压缩
- 使用设置自定义大小阈值
--max-size - 或者捕获指定元素而非整页截图
元素未找到:
- 先使用查找正确的选择器
snapshot.js - 检查元素是否为动态加载(可延长超时时间)
- 如果CSS选择器失败,尝试使用XPath选择器
脚本未找到:
- 确认当前处于正确的目录
- 检查脚本名称拼写
- 使用绝对路径:
bun /path/to/scripts/navigate.js