node-inspector
provides a familiar DevTools GUI that can be used in Chrome to debug Electron’s main process, however, because node-inspector
relies on some native Node modules they must be rebuilt to target the version of Electron you wish to debug. You can either rebuild the node-inspector
dependencies yourself, or let electron-inspector
do it for you, both approaches are covered in this document.
Note: At the time of writing the latest release of node-inspector
(0.12.8) can’t be rebuilt to target Electron 1.3.0 or later without patching one of its dependencies. If you use electron-inspector
it will take care of this for you.
electron-inspector
for Debuggingelectron-rebuild
, if you haven’t done so already.npm install electron-rebuild --save-dev
electron-inspector
npm install electron-inspector --save-dev
Launch Electron with the --debug
switch:
electron --debug=5858 your/app
or, to pause execution on the first line of JavaScript:
electron --debug-brk=5858 your/app
On macOS / Linux:
node_modules/.bin/electron-inspector
On Windows:
node_modules\\.bin\\electron-inspector
electron-inspector
will need to rebuild node-inspector
dependencies on the first run, and any time you change your Electron version. The rebuild process may require an internet connection to download Node headers and libs, and may take a few minutes.
Open http://127.0.0.1:8080/debug?ws=127.0.0.1:8080&port=5858 in the Chrome browser. You may have to click pause if starting with --debug-brk
to force the UI to update.
node-inspector
for Debuggingnode-inspector
$ npm install node-inspector
node-pre-gyp
$ npm install node-pre-gyp
node-inspector
v8
modules for ElectronNote: Update the target argument to be your Electron version number
$ node_modules/.bin/node-pre-gyp --target=1.2.5 --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=1.2.5 --runtime=electron --fallback-to-build --directory node_modules/v8-profiler/ --dist-url=https://atom.io/download/atom-shell reinstall
See also How to install native modules.
You can either start Electron with a debug flag like:
$ electron --debug=5858 your/app
or, to pause your script on the first line:
$ electron --debug-brk=5858 your/app
node-inspector
server using Electron$ ELECTRON_RUN_AS_NODE=true path/to/electron.exe node_modules/node-inspector/bin/inspector.js
Open http://127.0.0.1:8080/debug?ws=127.0.0.1:8080&port=5858 in the Chrome browser. You may have to click pause if starting with --debug-brk
to see the entry line.
© 2013–2017 GitHub Inc.
Licensed under the MIT license.
https://electron.atom.io/docs/tutorial/debugging-main-process-node-inspector/