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: >-4 Expert in Electron framework, desktop app development, IPC, and cross-platform packaging.5 Use when the user mentions desktop, Node.js, cross platform, Windows, macOS, or Linux, or6 when the task involves Electron Architecture, Process Types, IPC Communication, or App7 Lifecycle.8allowed-tools:9 - Read10 - Write11 - Edit12 - Bash13 - Grep14 - Glob15version: 1.1.016tags: [desktop, electron, nodejs, cross-platform, windows, macos, linux]17category: frameworks18phase: 619author: PCL Stdlib Team20metadata:21 source: https://skillmd.com/skills/personamanagmentlayer/electron-expert22---2324# Electron Expert2526You are an expert in Electron framework, desktop application development, and cross-platform packaging.2728## Core Concepts2930### Electron Architecture3132- **Main Process**: Node.js environment, manages app lifecycle and native APIs33- **Renderer Process**: Chromium browser, renders UI (HTML/CSS/JS)34- **Preload Scripts**: Bridge between main and renderer, context isolation35- **IPC (Inter-Process Communication)**: Message passing between processes36- **Context Isolation**: Security boundary between renderer and Node.js37- **Native Modules**: Node.js addons for system-level access3839### Process Types4041- **Main Process**: Single process, creates BrowserWindows, handles system events42- **Renderer Process**: One per BrowserWindow, isolated from each other43- **Utility Process**: Worker processes for heavy tasks (Electron 20+)44- **Service Workers**: Background scripts for web content4546### IPC Communication4748- **ipcMain**: Main process receiver (handle, on)49- **ipcRenderer**: Renderer process sender (invoke, send)50- **contextBridge**: Expose APIs to renderer safely51- **Remote Module**: Legacy, deprecated (use IPC instead)5253### App Lifecycle54551. `ready` - App initialization complete562. `window-all-closed` - All windows closed573. `before-quit` - Before app quits584. `will-quit` - App is about to quit595. `quit` - App has quit6061### Security Considerations6263- Enable context isolation64- Disable Node.js integration in renderer65- Use preload scripts with contextBridge66- Validate all IPC messages67- Implement Content Security Policy (CSP)68- Use sandboxing when possible69- Keep Electron updated7071## Best Practices7273### Security7475- Always enable context isolation76- Disable nodeIntegration in renderer77- Use preload scripts with contextBridge78- Validate all IPC input79- Implement Content Security Policy80- Keep Electron updated81- Use sandbox mode when possible82- Never load remote content without verification83- Sign your applications (macOS/Windows)8485### Performance8687- Use efficient IPC patterns (invoke/handle over send/on)88- Lazy load windows and modules89- Implement proper resource cleanup90- Use web workers for heavy computation91- Optimize renderer process code92- Minimize main process blocking operations93- Use v8 snapshots for faster startup94- Profile with Chrome DevTools9596### Code Organization9798- Separate main and renderer code99- Use TypeScript for type safety100- Implement proper error handling101- Create reusable IPC handlers102- Use configuration files103- Implement logging (electron-log)104- Follow Electron security guidelines105- Document IPC API thoroughly106107### Cross-Platform108109- Test on all target platforms110- Use platform-specific code when needed111- Handle platform differences (menus, shortcuts)112- Use path.join for file paths113- Respect OS conventions (macOS menu bar)114- Use platform-specific icons115- Handle file associations properly116117## Anti-Patterns118119### Security Anti-Patterns120121- Enabling nodeIntegration without context isolation122- Using remote module (deprecated)123- Loading untrusted remote content124- Exposing entire Node.js API to renderer125- Not validating IPC messages126- Disabling web security127- Using eval or new Function in renderer128129### Code Anti-Patterns130131- Blocking main process with heavy operations132- Not cleaning up event listeners133- Memory leaks from retained windows134- Synchronous IPC (ipcRenderer.sendSync)135- Not handling errors in IPC handlers136- Hardcoding platform-specific paths137- Not using preload scripts138139### Bad Code Example140141```javascript142// DON'T: Insecure configuration143const window = new BrowserWindow({144 webPreferences: {145 nodeIntegration: true,146 contextIsolation: false,147 enableRemoteModule: true, // deprecated148 },149});150151// Renderer can now access entire Node.js API - dangerous!152153// DO: Secure configuration154const window = new BrowserWindow({155 webPreferences: {156 preload: path.join(__dirname, 'preload.js'),157 contextIsolation: true,158 nodeIntegration: false,159 sandbox: true,160 },161});162163// Use preload script with contextBridge for controlled API exposure164```165166## Reference Documentation167168Detailed material lives alongside this skill and is read on demand:169170- [Code Examples](references/EXAMPLES.md) — Basic Electron App Structure, Advanced IPC Communication, Native Menus, Auto Updates (electron-updater), Electron Builder Configuration171172## Resources173174### Documentation175176- [Electron Documentation](https://www.electronjs.org/docs)177- [Electron API Demos](https://github.com/electron/electron-api-demos)178- [Electron Security Guidelines](https://www.electronjs.org/docs/latest/tutorial/security)179- [Process Model](https://www.electronjs.org/docs/latest/tutorial/process-model)180181### Tools & Libraries182183- [electron-builder](https://www.electron.build/) - Packaging and distribution184- [electron-updater](https://www.electron.build/auto-update) - Auto-updates185- [electron-log](https://github.com/megahertz/electron-log) - Logging186- [electron-store](https://github.com/sindresorhus/electron-store) - Data persistence187- [electron-reload](https://github.com/yan-foto/electron-reload) - Hot reload188- [electron-devtools-installer](https://github.com/MarshallOfSound/electron-devtools-installer)189190### UI Frameworks191192- [React](https://react.dev/) with Electron193- [Vue.js](https://vuejs.org/) with Electron194- [Svelte](https://svelte.dev/) with Electron195- [Angular](https://angular.io/) with Electron196197### Community & Resources198199- [Electron Fiddle](https://www.electronjs.org/fiddle) - Playground200- [Awesome Electron](https://github.com/sindresorhus/awesome-electron)201- [Electron Discord](https://discord.com/invite/electron)202- [r/electronjs](https://reddit.com/r/electronjs)203204### Popular Electron Apps205206- Visual Studio Code207- Slack208- Discord209- Figma210- Obsidian211- Notion