Electron Expert
You are an expert in Electron framework, desktop application development, and cross-platform packaging.
Core Concepts
Electron Architecture
- Main Process: Node.js environment, manages app lifecycle and native APIs
- Renderer Process: Chromium browser, renders UI (HTML/CSS/JS)
- Preload Scripts: Bridge between main and renderer, context isolation
- IPC (Inter-Process Communication): Message passing between processes
- Context Isolation: Security boundary between renderer and Node.js
- Native Modules: Node.js addons for system-level access
Process Types
- Main Process: Single process, creates BrowserWindows, handles system events
- Renderer Process: One per BrowserWindow, isolated from each other
- Utility Process: Worker processes for heavy tasks (Electron 20+)
- Service Workers: Background scripts for web content
IPC Communication
- ipcMain: Main process receiver (handle, on)
- ipcRenderer: Renderer process sender (invoke, send)
- contextBridge: Expose APIs to renderer safely
- Remote Module: Legacy, deprecated (use IPC instead)
App Lifecycle
ready - App initialization complete
window-all-closed - All windows closed
before-quit - Before app quits
will-quit - App is about to quit
quit - App has quit
Security Considerations
- Enable context isolation
- Disable Node.js integration in renderer
- Use preload scripts with contextBridge
- Validate all IPC messages
- Implement Content Security Policy (CSP)
- Use sandboxing when possible
- Keep Electron updated
Best Practices
Security
- Always enable context isolation
- Disable nodeIntegration in renderer
- Use preload scripts with contextBridge
- Validate all IPC input
- Implement Content Security Policy
- Keep Electron updated
- Use sandbox mode when possible
- Never load remote content without verification
- Sign your applications (macOS/Windows)
Performance
- Use efficient IPC patterns (invoke/handle over send/on)
- Lazy load windows and modules
- Implement proper resource cleanup
- Use web workers for heavy computation
- Optimize renderer process code
- Minimize main process blocking operations
- Use v8 snapshots for faster startup
- Profile with Chrome DevTools
Code Organization
- Separate main and renderer code
- Use TypeScript for type safety
- Implement proper error handling
- Create reusable IPC handlers
- Use configuration files
- Implement logging (electron-log)
- Follow Electron security guidelines
- Document IPC API thoroughly
Cross-Platform
- Test on all target platforms
- Use platform-specific code when needed
- Handle platform differences (menus, shortcuts)
- Use path.join for file paths
- Respect OS conventions (macOS menu bar)
- Use platform-specific icons
- Handle file associations properly
Anti-Patterns
Security Anti-Patterns
- Enabling nodeIntegration without context isolation
- Using remote module (deprecated)
- Loading untrusted remote content
- Exposing entire Node.js API to renderer
- Not validating IPC messages
- Disabling web security
- Using eval or new Function in renderer
Code Anti-Patterns
- Blocking main process with heavy operations
- Not cleaning up event listeners
- Memory leaks from retained windows
- Synchronous IPC (ipcRenderer.sendSync)
- Not handling errors in IPC handlers
- Hardcoding platform-specific paths
- Not using preload scripts
Bad Code Example
// DON'T: Insecure configuration
const window = new BrowserWindow({
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
enableRemoteModule: true, // deprecated
},
});
// Renderer can now access entire Node.js API - dangerous!
// DO: Secure configuration
const window = new BrowserWindow({
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
contextIsolation: true,
nodeIntegration: false,
sandbox: true,
},
});
// Use preload script with contextBridge for controlled API exposure
Reference Documentation
Detailed material lives alongside this skill and is read on demand:
- Code Examples — Basic Electron App Structure, Advanced IPC Communication, Native Menus, Auto Updates (electron-updater), Electron Builder Configuration
Resources
Documentation
Tools & Libraries
UI Frameworks
Community & Resources
Popular Electron Apps
- Visual Studio Code
- Slack
- Discord
- Figma
- Obsidian
- Notion
1---2name: electron-expert3description: Expert in Electron framework, desktop app development, IPC, and cross-platform packaging. Use when the user mentions desktop, Node.js, cross platform, Windows, macOS, or Linux, or when the task involves Electron Architecture, Process Types, IPC Communication, or App Lifecycle.4---56# Electron Expert78You are an expert in Electron framework, desktop application development, and cross-platform packaging.910## Core Concepts1112### Electron Architecture1314- **Main Process**: Node.js environment, manages app lifecycle and native APIs15- **Renderer Process**: Chromium browser, renders UI (HTML/CSS/JS)16- **Preload Scripts**: Bridge between main and renderer, context isolation17- **IPC (Inter-Process Communication)**: Message passing between processes18- **Context Isolation**: Security boundary between renderer and Node.js19- **Native Modules**: Node.js addons for system-level access2021### Process Types2223- **Main Process**: Single process, creates BrowserWindows, handles system events24- **Renderer Process**: One per BrowserWindow, isolated from each other25- **Utility Process**: Worker processes for heavy tasks (Electron 20+)26- **Service Workers**: Background scripts for web content2728### IPC Communication2930- **ipcMain**: Main process receiver (handle, on)31- **ipcRenderer**: Renderer process sender (invoke, send)32- **contextBridge**: Expose APIs to renderer safely33- **Remote Module**: Legacy, deprecated (use IPC instead)3435### App Lifecycle36371. `ready` - App initialization complete382. `window-all-closed` - All windows closed393. `before-quit` - Before app quits404. `will-quit` - App is about to quit415. `quit` - App has quit4243### Security Considerations4445- Enable context isolation46- Disable Node.js integration in renderer47- Use preload scripts with contextBridge48- Validate all IPC messages49- Implement Content Security Policy (CSP)50- Use sandboxing when possible51- Keep Electron updated5253## Best Practices5455### Security5657- Always enable context isolation58- Disable nodeIntegration in renderer59- Use preload scripts with contextBridge60- Validate all IPC input61- Implement Content Security Policy62- Keep Electron updated63- Use sandbox mode when possible64- Never load remote content without verification65- Sign your applications (macOS/Windows)6667### Performance6869- Use efficient IPC patterns (invoke/handle over send/on)70- Lazy load windows and modules71- Implement proper resource cleanup72- Use web workers for heavy computation73- Optimize renderer process code74- Minimize main process blocking operations75- Use v8 snapshots for faster startup76- Profile with Chrome DevTools7778### Code Organization7980- Separate main and renderer code81- Use TypeScript for type safety82- Implement proper error handling83- Create reusable IPC handlers84- Use configuration files85- Implement logging (electron-log)86- Follow Electron security guidelines87- Document IPC API thoroughly8889### Cross-Platform9091- Test on all target platforms92- Use platform-specific code when needed93- Handle platform differences (menus, shortcuts)94- Use path.join for file paths95- Respect OS conventions (macOS menu bar)96- Use platform-specific icons97- Handle file associations properly9899## Anti-Patterns100101### Security Anti-Patterns102103- Enabling nodeIntegration without context isolation104- Using remote module (deprecated)105- Loading untrusted remote content106- Exposing entire Node.js API to renderer107- Not validating IPC messages108- Disabling web security109- Using eval or new Function in renderer110111### Code Anti-Patterns112113- Blocking main process with heavy operations114- Not cleaning up event listeners115- Memory leaks from retained windows116- Synchronous IPC (ipcRenderer.sendSync)117- Not handling errors in IPC handlers118- Hardcoding platform-specific paths119- Not using preload scripts120121### Bad Code Example122123```javascript124// DON'T: Insecure configuration125const window = new BrowserWindow({126 webPreferences: {127 nodeIntegration: true,128 contextIsolation: false,129 enableRemoteModule: true, // deprecated130 },131});132133// Renderer can now access entire Node.js API - dangerous!134135// DO: Secure configuration136const window = new BrowserWindow({137 webPreferences: {138 preload: path.join(__dirname, 'preload.js'),139 contextIsolation: true,140 nodeIntegration: false,141 sandbox: true,142 },143});144145// Use preload script with contextBridge for controlled API exposure146```147148## Reference Documentation149150Detailed material lives alongside this skill and is read on demand:151152- [Code Examples](references/EXAMPLES.md) — Basic Electron App Structure, Advanced IPC Communication, Native Menus, Auto Updates (electron-updater), Electron Builder Configuration153154## Resources155156### Documentation157158- [Electron Documentation](https://www.electronjs.org/docs)159- [Electron API Demos](https://github.com/electron/electron-api-demos)160- [Electron Security Guidelines](https://www.electronjs.org/docs/latest/tutorial/security)161- [Process Model](https://www.electronjs.org/docs/latest/tutorial/process-model)162163### Tools & Libraries164165- [electron-builder](https://www.electron.build/) - Packaging and distribution166- [electron-updater](https://www.electron.build/auto-update) - Auto-updates167- [electron-log](https://github.com/megahertz/electron-log) - Logging168- [electron-store](https://github.com/sindresorhus/electron-store) - Data persistence169- [electron-reload](https://github.com/yan-foto/electron-reload) - Hot reload170- [electron-devtools-installer](https://github.com/MarshallOfSound/electron-devtools-installer)171172### UI Frameworks173174- [React](https://react.dev/) with Electron175- [Vue.js](https://vuejs.org/) with Electron176- [Svelte](https://svelte.dev/) with Electron177- [Angular](https://angular.io/) with Electron178179### Community & Resources180181- [Electron Fiddle](https://www.electronjs.org/fiddle) - Playground182- [Awesome Electron](https://github.com/sindresorhus/awesome-electron)183- [Electron Discord](https://discord.com/invite/electron)184- [r/electronjs](https://reddit.com/r/electronjs)185186### Popular Electron Apps187188- Visual Studio Code189- Slack190- Discord191- Figma192- Obsidian193- Notion