调试主进程
¥Debugging the Main Process
Electron 浏览器窗口中的 DevTools 只能调试在该窗口(即网页)中执行的 JavaScript。要调试在主进程中执行的 JavaScript,你需要使用外部调试器并使用 --inspect
或 --inspect-brk
开关启动 Electron。
¥The DevTools in an Electron browser window can only debug JavaScript that's
executed in that window (i.e. the web pages). To debug JavaScript that's
executed in the main process you will need to use an external debugger and
launch Electron with the --inspect
or --inspect-brk
switch.
命令行开关
¥Command Line Switches
使用以下命令行开关之一来启用主进程的调试:
¥Use one of the following command line switches to enable debugging of the main process:
--inspect=[port]
Electron 将监听指定 port
上的 V8 检查器协议消息,外部调试器需要连接到此端口。默认 port
是 9229
。
¥Electron will listen for V8 inspector protocol messages on the specified port
,
an external debugger will need to connect on this port. The default port
is
9229
.
electron --inspect=9229 your/app
--inspect-brk=[port]
与 --inspect
类似,但在 JavaScript 的第一行暂停执行。
¥Like --inspect
but pauses execution on the first line of JavaScript.
外部调试器
¥External Debuggers
你将需要使用支持 V8 检查器协议的调试器。
¥You will need to use a debugger that supports the V8 inspector protocol.
-
通过访问
chrome://inspect
并选择检查那里启动的 Electron 应用来连接 Chrome。¥Connect Chrome by visiting
chrome://inspect
and selecting to inspect the launched Electron app present there.