Chrome 调试指南
安装指南
通过 npm 安装
您可以使用 Node.js 的包管理工具 npm 来安装项目:
npm install chrome-debug
手动安装
如果您不想使用 npm,可以直接从 GitHub 下载源代码,并解压到您的项目目录中。
快速入门
初始化配置
在您的项目根目录下创建一个 config.js
文件:
module.exports = {
port: 9229,
chromePath: 'C:/Program Files/Google/Chrome/Application/chrome.exe'
};
启动调试服务器
在终端中运行以下命令启动调试服务:
node index.js
使用示例
基本用法
const { Debugger } = require('chrome-debug');
const debugger = new Debugger({
port: 9229,
configPath: 'config.js'
});
debugger.start().then(() => {
console.log('调试服务器已启动');
});
调试 Chrome 实例
const { chrome } = require('@modelcontextprotocol/chrome-remote-interface');
async function main() {
const chrome = await chrome.connect({
url: 'ws://localhost:9229',
target: {
browserContextId: 0
}
});
const title = await chrome.Runtime.getTitle();
console.log('页面标题:', title);
await chrome.close();
}
main().catch(console.error);
调试命令
启动新会话
chrome-debug --start --port=9230
连接到现有会话
chrome-debug --connect --url=http://localhost:9230
项目依赖
此项目使用了以下开源库:
许可证
此项目遵循 MIT 协议,具体内容请参阅 LICENSE 文件。
贡献指南
有关贡献的详细信息,请参阅 Contributing.md。
致谢
感谢以下资源和社区的支持: