2015-09-01 02:12:57 +00:00
|
|
|
# Debugging the Main Process
|
2014-08-20 02:01:43 +00:00
|
|
|
|
2015-09-09 21:11:06 +00:00
|
|
|
The browser window DevTools can only debug the renderer process scripts (i.e.
|
2015-09-01 02:12:57 +00:00
|
|
|
the web pages). In order to provide a way to debug the scripts from the main
|
|
|
|
process, Electron has provided the `--debug` and `--debug-brk` switches.
|
2014-08-20 02:01:43 +00:00
|
|
|
|
2015-09-01 02:12:57 +00:00
|
|
|
## Command Line Switches
|
|
|
|
|
|
|
|
Use the following command line switches to debug Electron's main process:
|
2014-08-20 02:43:41 +00:00
|
|
|
|
|
|
|
### `--debug=[port]`
|
2014-08-20 02:01:43 +00:00
|
|
|
|
2015-09-01 02:12:57 +00:00
|
|
|
When this switch is used Electron will listen for V8 debugger protocol
|
|
|
|
messages on `port`. The default `port` is `5858`.
|
2014-08-20 02:01:43 +00:00
|
|
|
|
2014-08-20 02:53:20 +00:00
|
|
|
### `--debug-brk=[port]`
|
2014-08-20 02:01:43 +00:00
|
|
|
|
|
|
|
Like `--debug` but pauses the script on the first line.
|
2014-08-20 02:43:41 +00:00
|
|
|
|
2015-09-01 02:12:57 +00:00
|
|
|
## Use node-inspector for Debugging
|
2014-08-20 02:43:41 +00:00
|
|
|
|
2016-03-31 05:17:50 +00:00
|
|
|
**Note:** Electron doesn't currently work very well
|
2015-09-01 02:12:57 +00:00
|
|
|
with node-inspector, and the main process will crash if you inspect the
|
2014-08-20 02:43:41 +00:00
|
|
|
`process` object under node-inspector's console.
|
|
|
|
|
2016-01-06 07:13:25 +00:00
|
|
|
### 1. Make sure you have [node-gyp required tools][node-gyp-required-tools] installed
|
|
|
|
|
|
|
|
### 2. Install [node-inspector][node-inspector]
|
|
|
|
|
|
|
|
```bash
|
2016-01-06 13:43:13 +00:00
|
|
|
$ npm install node-inspector
|
2016-01-06 07:13:25 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
### 3. Install a patched version of `node-pre-gyp`
|
2014-08-20 02:43:41 +00:00
|
|
|
|
|
|
|
```bash
|
2016-01-06 13:43:13 +00:00
|
|
|
$ npm install git+https://git@github.com/enlight/node-pre-gyp.git#detect-electron-runtime-in-find
|
2014-08-20 02:43:41 +00:00
|
|
|
```
|
|
|
|
|
2016-01-06 07:13:25 +00:00
|
|
|
### 4. Recompile the `node-inspector` `v8` modules for electron (change the target to your electron version number)
|
|
|
|
|
|
|
|
```bash
|
2016-03-12 00:26:29 +00:00
|
|
|
$ 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
|
2016-01-06 07:13:25 +00:00
|
|
|
```
|
|
|
|
|
2016-03-19 18:36:27 +00:00
|
|
|
See also [How to install native modules][how-to-install-native-modules].
|
2016-01-06 07:13:25 +00:00
|
|
|
|
|
|
|
### 5. Enable debug mode for Electron
|
2014-08-20 02:43:41 +00:00
|
|
|
|
2015-04-16 03:31:12 +00:00
|
|
|
You can either start Electron with a debug flag like:
|
2014-08-20 02:43:41 +00:00
|
|
|
|
|
|
|
```bash
|
2015-04-16 03:31:12 +00:00
|
|
|
$ electron --debug=5858 your/app
|
2014-08-20 02:43:41 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
or, to pause your script on the first line:
|
|
|
|
|
|
|
|
```bash
|
2015-04-16 03:31:12 +00:00
|
|
|
$ electron --debug-brk=5858 your/app
|
2014-08-20 02:43:41 +00:00
|
|
|
```
|
|
|
|
|
2016-01-19 05:49:49 +00:00
|
|
|
### 6. Start the [node-inspector][node-inspector] server using electron
|
2014-08-20 02:43:41 +00:00
|
|
|
|
2016-01-06 07:13:25 +00:00
|
|
|
```bash
|
2016-01-06 13:43:13 +00:00
|
|
|
$ ELECTRON_RUN_AS_NODE=true path/to/electron.exe node_modules/node-inspector/bin/inspector.js
|
2016-01-06 07:13:25 +00:00
|
|
|
```
|
|
|
|
|
2016-01-19 05:49:49 +00:00
|
|
|
### 7. Load the debugger UI
|
2016-01-06 07:13:25 +00:00
|
|
|
|
2016-04-22 13:53:26 +00:00
|
|
|
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.
|
2014-08-20 02:43:41 +00:00
|
|
|
|
2014-08-20 02:53:20 +00:00
|
|
|
[node-inspector]: https://github.com/node-inspector/node-inspector
|
2016-01-06 07:13:25 +00:00
|
|
|
[node-gyp-required-tools]: https://github.com/nodejs/node-gyp#installation
|
|
|
|
[how-to-install-native-modules]: using-native-node-modules.md#how-to-install-native-modules
|