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

调试应用

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

无论何时,您的Electron应用程序没有按照您设想的方式运行,一组调试工具也许可以帮助您找到代码的错误,性能瓶颈,或者优化的机会。

Application Debugging

Whenever your Electron application is not behaving the way you wanted it to, an array of debugging tools might help you find coding errors, performance bottlenecks, or optimization opportunities.

渲染进程

最广泛使用来调试指定渲染进程的工具是Chromium的开发者工具集。 它可以获取到所有的渲染进程,包括BrowserWindow的实例,BrowserView以及WebView。 您可以通过编程的方式在BrowserWindow的webContents中调用openDevTool()API来打开它们:

const { BrowserWindow } = require('electron')
let win = new BrowserWindow()
win.webContents.openDevTools()

谷歌为他们的开发者工具提供了杰出的文档 我们建议您熟悉它们,它们对于任何Electron开发者来说通常都是工具包中最强大的工具之一。

Renderer Process

The most comprehensive tool to debug individual renderer processes is the Chromium Developer Toolset. It is available for all renderer processes, including instances of BrowserWindow, BrowserView, and WebView. You can open them programmatically by calling the openDevTools() API on the webContents of the instance:

const { BrowserWindow } = require('electron')
let win = new BrowserWindow()
win.webContents.openDevTools()

Google offers excellent documentation for their developer tools. We recommend that you make yourself familiar with them - they are usually one of the most powerful utilities in any Electron Developer's tool belt.

主进程

调试主进程有点棘手, 因为您不能简单地打开开发者工具来调试它们。 多亏了谷歌和Node.js的紧密合作,Chromium开发者工具可以被用来调试Electron的主进程,否则你也许会遇到许多怪事就像require不能再控制台中显示。

如果想获取更多信息,可以看调试主进程的文档

Main Process

Debugging the main process is a bit trickier, since you cannot open developer tools for them. The Chromium Developer Tools can be used to debug Electron's main process thanks to a closer collaboration between Google / Chrome and Node.js, but you might encounter oddities like require not being present in the console.

For more information, see the Debugging the Main Process documentation.