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:
--debug=[port]
This switch will enable electron to listen on the specified port using the V8 debugging protocol. The default listening port is 5858.
--debug-brk=[port]
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.
-
Make sure it is installedNode gyp and its dependent tools
-
installnode-inspector
$ npm install node-inspector
-
installnode-pre-gyppatch
$ npm install git+https://[email protected]/enlight/node-pre-gyp.git#detect-electron-runtime-in-find
-
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)
-
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
-
Start with electronicnode-inspector
$ ELECTRON_RUN_AS_NODE=true path/to/electron.exe node_modules/node-inspector/bin/inspector.js
-
Loading debugger UI
Open in Chrome* http://127.0.0.1 :8080/debug?ws=127.0.0.1:8080&port=5858*。 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.