Ir para o conteúdo principal

Class: Debugger

Class: Debugger

Um transporte alternativo para o protocolo de depuração remoto do Chrome.

Process: Main
This class is not exported from the 'electron' module. It is only available as a return value of other methods in the Electron API.

As ferramentas de desenvolvedor do Chrome possuem special binding disponível no runtime do JavaScript que permite interagir com páginas e instrumentá-las.

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 === '') {


Eventos de instância

Event: 'detach'


  • event Event
  • reason string - Reason for detaching 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'


  • event Event
  • method string - Method name.
  • 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.

Métodos de Instância


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

Anexa o debugger à webContents.


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


Retira o debugger de 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.