Visual Studio Code Debug Electron main process Author: jekkay Category: Electron publish time: 2017-06-11 14:56
A • overview
This article was originally from the "Drop Stone": http://www.easysb.cn
For the JavaScript script in the window, we can debug through many plugins of Google Chrome, such as Devtools. But for the main program in electron, we need additional tools and methods for debugging.
For the electron program, you can start the program with the following command, to facilitate debugging by the external debugging tool through the V8 Debug Protocol, its command format is as follows:
# Elctron–debug=${port} Path/to/app
# Electron–debug-brk=${port} Path/to/app
The above two startup modes will allow the electron process to listen on the specified port. This allows the external debugging tool to debug the main program via the V8 Debug protocol through this port.
Two Vscode Commissioning
Using visual Studio code can debug the main program of electron, which is very convenient for our development and debugging, the method is as follows:
1) Under current project, create a file. Vscode/launch.json
2) Enter the following in the file
{"Version": "0.2.0", "configurations": [{"Name": "Debug Main Process", "type": "Node", "Request": "Launch", "CWD": "${ Workspaceroot} ",//" runtimeexecutable ":" ${workspaceroot}/node_modules/.bin/electron.cmd "," runtimeExecutable ":" C :/users/administrator.sky-20170407tcx/appdata/local/yarn/bin/electron.cmd "," program ":" ${workspaceroot}/main.js "}]}
Note the following two questions:
a) path issues If the electron is partially installed, perform a local environment path, such as "${workspaceroot}/node_modules/.bin/electron.cmd", if it is a global installation, first perform yarn global The bin looks at the global path and then fills in the path of the electron, for example, my global path is "c:/users/administrator.sky-20170407tcx/appdata/local/yarn/bin/ Electron.cmd ".
b) file name Linux and Windows file names will vary, Windows is Electron.cmd,linux is the electron, pay attention to distinguish, the best way is to go under the path to see what the hell is called!
3) Next, you can click the menu debug-start debugging, or you can press the shortcut key F5, start the program.
4) In order to test whether it can be a single-step operation, we lay a breakpoint on the first line of the main program, and then press F5 to start, the main program is broken in the first line of code, but also can be single-step, view variables and callStacks, etc., quite convenient, such as.
Visual Studio Code Debug Electron Master Process