类: Debugger
类: Debugger
备用的 Chrome 远程调试接口。
Process: Main
此类不从 'electron'
模块导出. 它只能作为 Electron API 中其他方法的返回值。
Chrome Developer Tools 在 JavaScript 运行时提供了一个 special binding , 允许与页面进行交互和检测。
const { BrowserWindow } = require('electron')
const win = new BrowserWindow()
try {
win.webContents.debugger.attach('1.1')
} catch (err) {
console.log('Debugger attach failed : ', err)
}
win.webContents.debugger.on('detach', (event, reason) => {
console.log('Debugger detached due to : ', reason)
})
win.webContents.debugger.on('message', (event, method, params) => {
if (method === 'Network.requestWillBeSent') {
if (params.request.url === 'https://www.github.com') {
win.webContents.debugger.detach()
}
}
})
win.webContents.debugger.sendCommand('Network.enable')
实例事件
Event: 'detach'
返回:
event
Eventreason
string - 拆离 debugger 的原因。
调试会话终止时激活 发生在对应的webContents
关闭或者调用 devtools 时,。
Event: 'message'
返回:
event
Eventmethod
string - 方法名。params
any - 远程调试协议中的 parameters 属性定义的事件参数。sessionId
string - 附加的调试会话的唯一标识符,将与从debugger.sendCommand
发送的值匹配。
当正在调试的目标发出条件检测事件时触发。