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