使用Playwright MCP Server和GitHub Copilot捕获、分析和报告浏览器控制台消息的轻量级工具。
快速捕获网页的控制台输出和运行时错误,用于:
该项目利用现代开发工具:
reports/文件夹中生成可读的人类输出console和pageerror事件该工具生成如下报告:
reports/flipkart_console_report.mdreports/amazon_console_report.md# 初始化项目
npm init -y
# 安装Playwright
npm install -D playwright
# 安装浏览器二进制文件
npx playwright install
此项目使用Playwright MCP Server与GitHub Copilot在代理模式下进行智能浏览器控制台分析和网络监控。
首先确保Playwright MCP服务器正在运行:
# 启动Playwright MCP服务器
# 服务器将监听命令并管理浏览器自动化
playwright-mcp-server start
@命令)在GitHub Copilot聊天中输入:
使用playwright MCP Server。对网页https://www.flipkart.com上的控制台错误信息进行分析,并将结果保存为markdown文件,位于reports文件夹下。
对于全面的网络监控:
使用playwright MCP Server。运行网站https://www.agoda.com加载网页的所有网络请求。按类型和大小细分提供完整的原始网络请求列表。就可能的原因和修复方案提供建议。写入markdown文件并附在reports文件夹下。
一旦发出命令,自动化过程就开始了:
对于控制台分析:
reports/文件夹下对于网络分析:
整个过程通过Playwright MCP服务器和GitHub Copilot的代理能力自动化。
创建capture.js:
const { chromium } = require('playwright');
(async () => {
const browser = await chromium.launch({ headless: true });
const context = await browser.newContext();
const page = await context.newPage();
const messages = [];
// 监听控制台消息
page.on('console', msg => {
const loc = msg.location ? msg.location() : null;
messages.push({
source: 'console',
level: msg.type(),
text: msg.text(),
location: loc
});
});
// 监听页面错误
page.on('pageerror', err => {
messages.push({
source: 'pageerror',
message: err.message,
stack: err.stack
});
});
// 导航并捕获
await page.goto('https://www.flipkart.com', { waitUntil: 'networkidle' });
await page.waitForTimeout(6000); // 允许运行时脚本执行
// 输出结果
console.log(JSON.stringify(messages, null, 2));
await browser.close();
})();
node capture.js
BrowserConsoleAnalysis/
├── 📄 README.md
├── 📄 capture.js
├── 📄 package.json
├── 📄 package-lock.json
├── 📂 reports/
│ ├── flipkart_console_report.md
│ ├── amazon_console_report.md
│ ├── agoda_network_requests_report.md
│ └── agoda_resource_timing.json
└── 📂 node_modules/
└── (依赖项)
// 启用跟踪
await context.tracing.start({ screenshots: true, snapshots: true });
// ...你的捕获逻辑...
// 保存跟踪
await context.tracing.stop({ path: 'trace.zip' });
const context = await browser.newContext({
recordHar: { path: 'network.har' }
});
// 添加参数解析
const url = process.argv[2] || 'https://www.example.com';
const timeout = parseInt(process.argv[3]) || 6000;
示例报告包含在此仓库中:
| 网站 | 类型 | 报告 |
|---|---|---|
| Flipkart | 控制台错误 | reports/flipkart_console_report.md |
| Amazon | 控制台错误 | reports/amazon_console_report.md |
| Agoda | 网络分析 | reports/agoda_network_requests_report.md |
| Agoda | 资源计时 | reports/agoda_resource_timing.json |
Saran Kumar
MIT许可证 - 欢迎出于任何目的使用此项目!
使用Playwright制作 ❤️
⭐ 如果您觉得它有用,请给这个仓库点赞!
</div>