2015-03-26 15:20:31 +00:00
|
|
|
# Debugging the main process
|
2014-08-20 02:01:43 +00:00
|
|
|
|
2015-03-26 15:20:31 +00:00
|
|
|
The devtools of browser window can only debug the renderer process scripts.
|
|
|
|
(I.e. the web pages.) In order to provide a way to debug the scripts of
|
2015-04-16 03:31:12 +00:00
|
|
|
the main process, Electron has provided the `--debug` and `--debug-brk`
|
2015-03-26 15:20:31 +00:00
|
|
|
switches.
|
2014-08-20 02:01:43 +00:00
|
|
|
|
2014-08-20 02:43:41 +00:00
|
|
|
## Command line switches
|
|
|
|
|
|
|
|
### `--debug=[port]`
|
2014-08-20 02:01:43 +00:00
|
|
|
|
2015-04-16 03:31:12 +00:00
|
|
|
When this switch is used Electron would listen for V8 debugger protocol
|
2014-08-20 02:53:20 +00:00
|
|
|
messages on `port`, the `port` is `5858` by default.
|
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
|
|
|
|
|
|
|
## Use node-inspector for debugging
|
|
|
|
|
2015-04-08 17:16:10 +00:00
|
|
|
__Note:__ Electron uses node v0.11.13, which currently doesn't work very well
|
2015-03-26 15:20:31 +00:00
|
|
|
with node-inspector, and the main process would crash if you inspect the
|
2014-08-20 02:43:41 +00:00
|
|
|
`process` object under node-inspector's console.
|
|
|
|
|
2014-08-20 02:53:20 +00:00
|
|
|
### 1. Start the [node-inspector][node-inspector] server
|
2014-08-20 02:43:41 +00:00
|
|
|
|
|
|
|
```bash
|
|
|
|
$ node-inspector
|
|
|
|
```
|
|
|
|
|
2015-04-16 03:31:12 +00:00
|
|
|
### 2. 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
|
|
|
```
|
|
|
|
|
|
|
|
### 3. Load the debugger UI
|
|
|
|
|
|
|
|
Open http://127.0.0.1:8080/debug?port=5858 in the Chrome browser.
|
|
|
|
|
2014-08-20 02:53:20 +00:00
|
|
|
[node-inspector]: https://github.com/node-inspector/node-inspector
|