The development tool devtools
Electron
browser window can only debug the JavaScript
executed in this window (such as the web
page). JavaScript
executed in the main process, we need to use an external debugger. Electron
provides --inspect
and --inspect-brk
switches to achieve this operation.
Command line switch
We can use the following command line switches to debug the main process of Electron
--inspect=[port]
: When this switch is usedElectron
, it will listenV8
engine relatedport
protocol information of the debugger, the defaultport
value5858
. For example, the following command:
electron --inspect=5858 .src/main.js
--inspect-brk=[port]
:--inspector
as 060c2d8c181c1a, but it will pause at the first line of theJavaScript
Main process debugging
.vscode/launch.json
file in the root directory and use the following configuration:
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Main Process",
"type": "node",
"request": "launch",
"cwd": "${workspaceRoot}",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron",
"windows": {
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd"
},
"args": ["."],
"outputCapture": "std"
}
]
}
Then VSCode
, click on the settings in the upper right corner, and the newly created launch.json
file will be opened, as shown below:
Then click the green triangle button in the upper left corner:
Then perform breakpoint debugging in the main.js
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。