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.每当您的Electron应用程序没有按您希望的方式运行时,一系列调试工具可能会帮助您发现编码错误、性能瓶颈或优化机会。
Renderer Process
The most comprehensive tool to debug individual renderer processes is the Chromium Developer Toolset. 调试单个渲染器进程的最全面的工具是Chromium Developer工具集。It is available for all renderer processes, including instances of 它适用于所有渲染器进程,包括BrowserWindow
, BrowserView
, and WebView
. BrowserWindow
、BrowserView
和WebView
的实例。You can open them programmatically by calling the 您可以通过调用实例的openDevTools()
API on the webContents
of the instance:webContents
上的openDevTools()
API以编程方式打开它们:
const { BrowserWindow } = require('electron')
const 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.我们建议您熟悉它们——它们通常是任何Electron Developer工具带中最强大的工具之一。
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 由于Google/Chrome和Node.js之间的密切合作,Chromium开发工具可以用于调试Electron的主进程,但您可能会遇到一些奇怪的情况,比如需要不在控制台中。require
not being present in the console.
For more information, see the Debugging the Main Process documentation.有关详细信息,请参阅调试主进程文档。
V8 Crashes
If the V8 context crashes, the DevTools will display this message.如果V8上下文崩溃,DevTools将显示此消息。
DevTools was disconnected from the page. Once page is reloaded, DevTools will automatically reconnect.
Chromium logs can be enabled via the 铬日志可以通过ELECTRON_ENABLE_LOGGING
environment variable. ELECTRON_ENABLE_LOGGING
环境变量启用。For more information, see the environment variables documentation.有关详细信息,请参阅环境变量文档。
Alternatively, the command line argument 或者,可以传递命令行参数--enable-logging
can be passed. --enable-logging
。More information is available in the command line switches documentation.命令行开关文档中提供了更多信息。