Skip to main content

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 --inspect or --inspect-brk switch.要调试在主进程中执行的JavaScript,您需要使用外部调试器并使用--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 port, an external debugger will need to connect on this port. Electron将侦听指定port上的V8检查器协议消息,需要在此端口上连接外部调试器。The default port is 5858.默认port5858

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中调试