May 25, 2021 Electron
The browser window's development tools can only debug the renderer's process scripts ( such as web pages).
To provide a way to debug the main process, Electron
--debug
--debug-brk
Use the following command-line switches to debug electron's main process:
--debug=[port]
When this switch is used for Electron, it listens for debugger protocol information about port in the
port
engine.
The default
port
is
5858
--debug-brk=[port]
Just
--debug
but the script is paused on the first line.
Note:
Electron's current support for node-inspector is not particularly good, and if you examine the process object
process
the main process crashes.
$ npm install node-inspector
node-pre-gyp
$ npm install git+https://[email protected]/enlight/node-pre-gyp.git#detect-electron-runtime-in-find
node-inspector
v8
Electron (modify the target parameter to your Electron version number)
$ node_modules/.bin/node-pre-gyp --target=0.36.2 --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.2 --runtime=electron --fallback-to-build --directory node_modules/v8-profiler/ --dist-url=https://atom.io/download/atom-shell reinstall
[How to install native modules] [how-to-install-native-modules].
You can also run Electron with debug parameters:
$ electron --debug=5858 your/app
Or, pause your script on the first line:
$ electron --debug-brk=5858 your/app
$ ELECTRON_RUN_AS_NODE=true path/to/electron.exe node_modules/node-inspector/bin/inspector.js