AgentSkillsCN

chrome-devtools

利用 Puppeteer CLI 脚本进行浏览器自动化、调试与性能分析。当您需要自动化浏览器操作、截取屏幕截图、分析性能、监控网络流量、执行网页爬虫、自动化表单填写,或进行 JavaScript 调试时,可使用此技能。

SKILL.md
--- frontmatter
name: chrome-devtools
description: Browser automation, debugging, and performance analysis using Puppeteer CLI scripts. Use for automating browsers, taking screenshots, analyzing performance, monitoring network traffic, web scraping, form automation, and JavaScript debugging.
license: Apache-2.0
version: 1.2.0

Chrome DevTools Agent Skill

Browser automation via Puppeteer scripts with persistent sessions. All scripts output JSON.

⚠️ MUST READ References

IMPORTANT: You MUST read these reference files for complete protocol. Do NOT skip.

  • ⚠️ MUST READ references/devtools-patterns.md — ARIA, screenshots, console, custom scripts
  • ⚠️ MUST READ references/cdp-domains.md — CDP domain reference
  • ⚠️ MUST READ references/puppeteer-reference.md — Puppeteer API reference
  • ⚠️ MUST READ references/performance-guide.md — Performance analysis guide
  • ⚠️ MUST READ scripts/README.md — Script options reference

Choosing Your Approach

ScenarioApproach
Source-available sitesRead source code first, write selectors directly
Unknown layoutsUse aria-snapshot.js for semantic discovery
Visual inspectionTake screenshots to verify rendering
Debug issuesCollect console logs, analyze with session storage

Quick Start

bash
cd .claude/skills/chrome-devtools/scripts
npm install
node navigate.js --url https://example.com
# Headless on Linux/WSL/CI; headed on macOS/Windows
# Linux/WSL: Run ./install-deps.sh first for Chrome system libraries

Session Persistence

Browser state persists via .browser-session.json. Scripts disconnect but keep browser running.

bash
node navigate.js --url https://example.com/login
node fill.js --selector "#email" --value "user@example.com"
node click.js --selector "button[type=submit]"
node navigate.js --url about:blank --close true   # Close when done

Available Scripts

All in .claude/skills/chrome-devtools/scripts/:

ScriptPurpose
navigate.jsNavigate to URLs
screenshot.jsCapture screenshots (auto-compress >5MB)
click.jsClick elements
fill.jsFill form fields
evaluate.jsExecute JS in page context
snapshot.jsExtract interactive elements (JSON)
aria-snapshot.jsGet ARIA accessibility tree (YAML with refs)
select-ref.jsInteract with elements by ARIA ref
console.jsMonitor console messages/errors
network.jsTrack HTTP requests/responses
performance.jsMeasure Core Web Vitals

Script Options (All scripts)

  • --headless false - Show browser window
  • --close true - Close browser completely
  • --timeout 30000 - Set timeout (ms)
  • --wait-until networkidle2 - Wait strategy

Common Patterns

bash
# Web scraping
node evaluate.js --url https://example.com --script "
  Array.from(document.querySelectorAll('.item')).map(el => ({
    title: el.querySelector('h2')?.textContent, link: el.querySelector('a')?.href
  }))" | jq '.result'

# Form automation
node fill.js --selector "#search" --value "query"
node click.js --selector "button[type=submit]"

# Performance
node performance.js --url https://example.com | jq '.vitals'

Local HTML Files

Never use file://. Serve via local server: npx serve ./dist -p 3000 &

Troubleshooting

ErrorSolution
Cannot find package 'puppeteer'Run npm install in scripts directory
libnss3.so missing (Linux)Run ./install-deps.sh
Element not foundUse snapshot.js to find correct selector
Script hangsUse --timeout 60000 or --wait-until load
Screenshot >5MBAuto-compressed; use --max-size 3 for lower
Session staleDelete .browser-session.json and retry

IMPORTANT Task Planning Notes

  • Always plan and break many small todo tasks
  • Always add a final review todo task to review the works done at the end to find any fix or enhancement needed