应用调试
¥Application Debugging
每当你的 Electron 应用未按你希望的方式运行时,一系列调试工具可能会帮助你发现编码错误、性能瓶颈或优化机会。
¥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.
渲染进程
¥Renderer Process
调试单个渲染器进程的最全面的工具是 Chromium 开发者工具集。它可用于所有渲染器进程,包括 BrowserWindow
、BrowserView
和 WebView
的实例。你可以通过在实例的 webContents
上调用 openDevTools()
API 以编程方式打开它们:
¥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')
const win = new BrowserWindow()
win.webContents.openDevTools()
Google 提供 其开发者工具的优秀文档。我们建议你熟悉它们 - 它们通常是任何 Electron 开发者工具带中最强大的实用程序之一。
¥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.
主进程
¥Main Process
调试主进程有点棘手,因为你无法为其打开开发者工具。由于 Google / Chrome 和 Node.js 之间的更密切合作,Chromium 开发者工具可以实现 用于调试 Electron 的主进程,但你可能会遇到诸如 require
之类的奇怪情况没有出现在控制台中。
¥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.
V8 崩溃
¥V8 Crashes
如果 V8 上下文崩溃,DevTools 将显示此消息。
¥If the V8 context crashes, the DevTools will display this message.
DevTools was disconnected from the page. Once page is reloaded, DevTools will automatically reconnect.
可以通过 ELECTRON_ENABLE_LOGGING
环境变量启用 Chromium 日志。有关详细信息,请参阅 环境变量文档。
¥Chromium logs can be enabled via the ELECTRON_ENABLE_LOGGING
environment variable. For more information, see the environment variables documentation.
或者,可以传递命令行参数 --enable-logging
。更多信息请参见 命令行开关文档。
¥Alternatively, the command line argument --enable-logging
can be passed. More information is available in the command line switches documentation.