Electron Guide – debug main process


Debug main process

Devtools for browser windows can only debug scripts for rendering processes (such as web pages). To provide a way to debug scripts in the main process, electron provides–debugas well as–debug-brkOption switch.

command line switch

Use the following command line to switch to debug electron’s main process mode:


This switch will enable electron to listen on the specified port using the V8 debugging protocol. The default listening port is 5858.


be similar to–debugBut this switch pauses execution on the first line of the script.

Use node inspector to debug

be careful:The current electron and node inspector don’t work very well, and when you check in the node inspector’s consoleprocessObject, the main process will hang up.

  1. Make sure it is installedNode gyp and its dependent tools

  2. installnode-inspector

    $ npm install node-inspector
  3. installnode-pre-gyppatch

    $ npm install git+https://[email protected]/enlight/node-pre-gyp.git#detect-electron-runtime-in-find
  4. Recompilenode-inspector V8Module (change compilation target to your electron version number)

    $ node_modules/.bin/node-pre-gyp --target=0.36.11 --runtime=electron --fallback-to-build --directory node_modules/v8-debug/ --dist-url=https://atom.io/download/atom-shell reinstall
    $ node_modules/.bin/node-pre-gyp --target=0.36.11 --runtime=electron --fallback-to-build --directory node_modules/v8-profiler/ --dist-url=https://atom.io/download/atom-shell reinstall
    Refer to [how to install a local module]( http://electron.atom.io/docs/tutorial/using-native-node-modules#how -to-install-native-modules)
  5. Turn on electron debug mode

    You can use a debug flag to turn on the electron, for example:
    $ electron --debug=5858 your/app
    Or pause on the first line of the script
    $ electron --debug-brk=5858 your/app
  6. Start with electronicnode-inspector

    $ ELECTRON_RUN_AS_NODE=true path/to/electron.exe node_modules/node-inspector/bin/inspector.js
  7. Loading debugger UI

    Open in Chrome* :8080/debug?ws=*。  If you use debug BRK to start, you have to click pause to see the full line.

This article is translated from [here](http://electron.atom.io/docs/tutorial/debugging-main-process/)
Unauthorized reprint is prohibited.

For more articles, please visit my blog:@gihub, @coding