当前位置: 首页 > 文档资料 > Electron 中文文档 >

调试主进程

优质
小牛编辑
115浏览
2023-12-01

Electron 浏览器窗口中的 DevTools 只能调试 在该窗口中执行的 JavaScript (即 web 页面) 。 为了提供一个可以调试主进程的方法,Electron 提供了 --inspect--inspect-brk 开关。

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). 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.

命令行开关

使用如下的命令行开关来调试 Electron 的主进程:

Command Line Switches

Use one of the following command line switches to enable debugging of the main process:

--inspect=[port]

当这个开关用于 Electron 时,它将会监听 V8 引擎中有关 port 的调试器协议信息。 默认的port5858

electron --inspect=5858 your/app

--inspect=[port]

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 5858.

electron --inspect=5858 your/app

--inspect-brk=[port]

--inspector 一样,但是会在JavaScript 脚本的第一行暂停运行。

--inspect-brk=[port]

Like --inspect but pauses execution on the first line of JavaScript.

外部调试器

你需要使用一个支持 V8 调试协议的调试器

  • 通过访问 chrome://inspect 来连接 Chrome 并在那里选择需要检查的Electron 应用程序。
  • 使用 VSCode 进行主进程调试

External Debuggers

You will need to use a debugger that supports the V8 inspector protocol.

  • Connect Chrome by visiting chrome://inspect and selecting to inspect the launched Electron app present there.
  • Debugging the Main Process in VSCode