When to Use
User wants to automatically analyze a website URL for performance metrics, accessibility, SEO, or best practices without manual Chrome DevTools interaction.
Core Rules
- 1. Verify prerequisites — Check Node.js (v18+) and packages installed: INLINECODE0
- 2. Run Lighthouse audit — Execute
node automation-script.js <URL> [--mobile] [--output=DIR] to collect all metrics.
- 3. Extract and present metrics — Use tables for scores (0-100) and metrics with status indicators (⚪ Good, 🟡 Warning, 🔴 Critical).
- 4. Identify critical issues — Flag metrics outside thresholds: LCP>2.5s, CLS>0.1, INP>200ms, TBT>200ms, Performance<50.
- 5. Provide actionable fixes — For each issue, include specific code fixes from
audit-checklist.md and metrics-reference.md.
- 6. Save results — Store JSON and HTML reports in
./results/. Ask user before saving to memory for tracking.
- 7. Handle errors gracefully — If audit fails, check
troubleshooting.md for common solutions (Chrome not found, ES module errors, memory issues).
Quick Reference
| Topic | File |
|---|
| Automation script | INLINECODE6 |
| Metrics & thresholds |
metrics-reference.md |
| Fix checklists |
audit-checklist.md |
| Setup guide |
setup.md |
| Quick start |
quick-start.md |
| Troubleshooting |
troubleshooting.md |
| Memory tracking |
memory-template.md |
Data Storage
After analysis, offer to save: URL, timestamp, scores, critical issues, report path. Always ask before saving to memory.
Security & Privacy
- - Runs locally in headless Chrome — no external data transmission
- Warn before analyzing authenticated URLs
- JSON reports contain URL structure — handle sensitive paths carefully
Common Commands
CODEBLOCK0
Troubleshooting Quick Reference
| Error | Solution |
|---|
| "lighthouse is not a function" | Add "type": "module" to package.json |
| "Chrome not found" |
Install Chrome or use
npm install puppeteer |
| "JavaScript heap out of memory" | Run with
node --max-old-space-size=4096 |
| "Port already in use" | Specify different port in script config |
使用时机
用户希望自动分析网站URL的性能指标、可访问性、SEO或最佳实践,无需手动操作Chrome DevTools。
核心规则
- 1. 验证前置条件 — 检查Node.js(v18+)及已安装的包:node --version && npm list lighthouse chrome-launcher
- 2. 运行Lighthouse审计 — 执行node automation-script.js [--mobile] [--output=DIR]收集所有指标。
- 3. 提取并呈现指标 — 使用表格展示评分(0-100)及带有状态指示符的指标(⚪ 良好、🟡 警告、🔴 严重)。
- 4. 识别关键问题 — 标记超出阈值的指标:LCP>2.5秒、CLS>0.1、INP>200毫秒、TBT>200毫秒、性能评分<50。
- 5. 提供可操作的修复方案 — 针对每个问题,包含来自audit-checklist.md和metrics-reference.md的具体代码修复方案。
- 6. 保存结果 — 将JSON和HTML报告存储在./results/目录中。保存到内存前需征得用户同意。
- 7. 优雅处理错误 — 若审计失败,查阅troubleshooting.md中的常见解决方案(未找到Chrome、ES模块错误、内存问题)。
快速参考
| 主题 | 文件 |
|---|
| 自动化脚本 | automation-script.js |
| 指标与阈值 |
metrics-reference.md |
| 修复清单 | audit-checklist.md |
| 设置指南 | setup.md |
| 快速入门 | quick-start.md |
| 故障排除 | troubleshooting.md |
| 内存跟踪 | memory-template.md |
数据存储
分析完成后,提供保存选项:URL、时间戳、评分、关键问题、报告路径。保存到内存前始终征得用户同意。
安全与隐私
- - 在无头Chrome中本地运行 — 无外部数据传输
- 分析需要认证的URL前发出警告
- JSON报告包含URL结构 — 谨慎处理敏感路径
常用命令
bash
快速审计(桌面端)
node automation-script.js https://example.com
移动端模拟
node automation-script.js https://example.com --mobile
自定义输出目录
node automation-script.js https://example.com --output=./reports
直接使用Lighthouse CLI
lighthouse https://example.com --output=json --output-path=report.json
故障排除快速参考
| 错误 | 解决方案 |
|---|
| lighthouse is not a function | 在package.json中添加type: module |
| Chrome not found |
安装Chrome或使用npm install puppeteer |
| JavaScript heap out of memory | 使用node --max-old-space-size=4096运行 |
| Port already in use | 在脚本配置中指定不同端口 |