调试器 | Debugger

Class: Debugger

Chrome远程调试协议的备用传输方式。

过程:主

Chrome开发者工具在JavaScript运行时有一个特殊的绑定,允许与页面进行交互并对它们进行测试。

const {BrowserWindow} = require('electron') let 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')

Instance Methods

debugger.attach([protocolVersion])

  • protocolVersion 字符串(可选) - 请求的调试协议版本。

将调试器附加到webContents

debugger.isAttached()

返回Boolean- 调试器是否附加到webContents

debugger.detach()

从调试器中分离出来webContents

debugger.sendCommand(method[, commandParams, callback])

  • method 字符串 - 方法名称应该是远程调试协议定义的方法之一。

将给定的命令发送到调试目标。

Instance Events

Event: ‘detach’

  • event Event

调试会话终止时发出。这种情况发生在webContents关闭或devtools被调用时webContents

Event: ‘message’

  • event 事件

每当调试目标问题检测仪器事件时发出。