Zum Hauptteil springen

Class: Debugger

Class: Debugger

Ein alternativer Transport für Chromes Remote-Debugging-Protokoll.

Prozess: Haupt
Diese Klasse wird nicht aus dem 'electron' -Modul exportiert. Es ist nur als Rückgabewert anderer Methoden in der Electron-API verfügbar.

Chrome Developer Tools has a special binding available at JavaScript runtime that allows interacting with pages and instrumenting them.

const { BrowserWindow } = require('electron')
const win = new BrowserWindow()

try {
} 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') {



Event: 'detach'

Kehrt zurück:

  • event Event
  • reason string - Grund für das Lösen von Debugger.

Emitted when the debugging session is terminated. This happens either when webContents is closed or devtools is invoked for the attached webContents.

Event: 'message'

Kehrt zurück:

  • event Event
  • method string - Methodenname.
  • params any - Event parameters defined by the 'parameters' attribute in the remote debugging protocol.
  • sessionId string - Unique identifier of attached debugging session, will match the value sent from debugger.sendCommand.

Emitted whenever the debugging target issues an instrumentation event.

Beispiel Methoden


  • protocolVersion string (optional) - Requested debugging protocol version.

Attaches the debugger to the webContents.


Returns boolean - Whether a debugger is attached to the webContents.


Detaches the debugger from the webContents.

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

  • method string - Method name, should be one of the methods defined by the remote debugging protocol.
  • commandParams any (optional) - JSON object with request parameters.
  • sessionId string (optional) - send command to the target with associated debugging session id. The initial value can be obtained by sending Target.attachToTarget message.

Returns Promise<any> - A promise that resolves with the response defined by the 'returns' attribute of the command description in the remote debugging protocol or is rejected indicating the failure of the command.

Send given command to the debugging target.