Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Electron main process debugging


May 25, 2021 Electron


Table of contents


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

The command line switch

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.

Use node-inspector to debug

Note: Electron's current support for node-inspector is not particularly good, and if you examine the process object process the main process crashes.

1. Make sure you have the tools you need for node-gyp installed

2. Install node-inspector

$ npm install node-inspector

3. Install node-pre-gyp

$ npm install git+https://[email protected]/enlight/node-pre-gyp.git#detect-electron-runtime-in-find

4. Recompile the 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].

5. Turn on Electron's debug mode

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

6. Use Electron to turn on the node-inspector service

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

7. Load the debugger interface

Open the page in Chrome http://127.0.0.1:8080/debug?ws=127.0.0.1:8080&port=5858