Electron Development Tools
For Electron development tools, VS Code is recommended; if you are not yet familiar with VS Code you can refer to our VS Code Tutorial.
VS Code download address:https://code.visualstudio.com/.
VS Code itself is built with Electron, so it has natural support advantages for Electron development:
- Built-in terminal integration
- Strong debugging features
- Rich plugin ecosystem
- Git integration
- IntelliSense smart hints
- Completely free and open source
Recommended must-install VS Code extensions
| Plugin name | Description |
|---|---|
| Electron Snippets | Provides code snippets and autocompletion for the Electron API |
| Prettier – Code Formatter | Unify code style with automatic formatting |
| ESLint | Check for syntax errors and style issues |
| Debugger for Chrome | Lets you debug the front-end renderer process in VS Code |
| Node.js Modules Intellisense | Auto-suggest Node.js module functions |
| Path Intellisense | Smart file path suggestions |
| npm Intellisense | Auto-suggest npm package names |
| Auto Rename Tag / Auto Close Tag | Smart HTML tag completion |
| GitLens | Improve the Git code version visualization experience |
Chrome DevTools debugging (renderer process)
Electron's renderer process is actually just a Chromium browser page,
So you can debug it directly with Chrome DevTools, just like debugging a web page.
Enable DevTools
in main.js add this when creating the window in:
Example
const
win
=
new
BrowserWindow
(
{
width
:
800
,
height
:
600
}
)
;
win.
loadFile
(
'index.html'
)
;
// Open Developer Tools
win.
webContents
.
openDevTools
(
)
;
What you can debug
- HTML / CSS / JS code
- Network requests (Network)
- Console logs (Console)
- DOM structure
- Performance analysis (Performance)
- Memory leaks (Memory)
Tip
Debugging the renderer process is almost identical to Chrome, so:
- You can use the
console.log()Output debug information - You can also directly use Chrome's shortcut (
Cmd + Option + I/Ctrl + Shift + I) to open DevTools
Electron main process debugging tips
The main process is not a web page but a Node.js environment, so it is debugged differently from a web page.
Method 1: Use the built-in VS Code debugger
Create in the project root directory .vscode/launch.json files.
The content is as follows (ready to use):
{
"version": "0.2.0",
"configurations": [
{
"name": "Electron 主进程调试",
"type": "node",
"request": "launch",
"program": "${workspaceFolder}/node_modules/electron/dist/electron.js",
"args": ["."],
"outputCapture": "std",
"runtimeExecutable": null,
"cwd": "${workspaceFolder}"
}
]
}
Then in
main.jsset breakpoints and click Debug to start.
Method 2: Command-line remote debugging
Add a parameter at startup:
electron . --inspect=5858
Then open in the Chrome address bar:
chrome://inspect
to remotely connect to the main process and debug with breakpoints just like Node.js.
Summary of common debugging tips
| Debugging target | Tool / Method | Description |
|---|---|---|
| Window UI lag | Chrome DevTools → Performance | Analyze rendering time and JS execution bottlenecks |
| Window crashes on startup | Add try/catch in the main process or use electron-log Logging |
Catch main process exceptions |
| IPC communication errors | in ipcMain / ipcRenderer Add logs in |
Debug main-renderer communication |
| File path errors | Use path.join(__dirname, 'xxx') |
Avoid relative path issues |
| Packaging debugging | Use electron-builder --dir Build in directory mode first |
Can be run and debugged directly |
Recommended advanced tools
| Tool | Purpose |
|---|---|
| Electron Forge | Officially recommended scaffolding tool to quickly create and package projects |
| Electron Builder | A powerful packaging and publishing tool |
| Electron Reload | Automatically refreshes the app after file changes |
| Spectron | Used for automated testing of Electron apps |
| Devtron | Official Electron debugging extension for analyzing internal app state |
| React / Vue DevTools | If you use a front-end framework, debugging component state is very convenient |
Write with VS Code, inspect with DevTools, debug with launch.json, package with Builder - this is the complete toolchain of a professional Electron developer.