← 返回
开发者工具
中文
Electron
Build Electron desktop apps with secure architecture and common pitfall avoidance.
构建具有安全架构并避免常见陷阱的 Electron 桌面应用。
ivangdavila
开发者工具
clawhub
v1.0.0 1 版本 100000 Key: 无需
#latest
概述
Security Non-Negotiables
nodeIntegration: false is mandatory — renderer with Node.js access means XSS = full system compromisecontextIsolation: true is mandatory — separates preload context from renderer- Whitelist IPC channels explicitly — never forward arbitrary channel names from renderer
- Validate all IPC message content — renderer is untrusted, treat like external API input
- Never use
eval() or new Function() in renderer — defeats all security boundaries
Preload Script Rules
contextBridge.exposeInMainWorld() is the only safe bridge — raw ipcRenderer exposure is vulnerable- Clone data before passing across bridge — prevents prototype pollution attacks
- Minimal API surface — expose specific functions, not generic send/receive
Architecture Traps
webPreferences locked after window creation — can't enable nodeIntegration later- Blocking main process freezes ALL windows — async everything, no sync file operations
- Each BrowserWindow is separate renderer process — can't share JS variables directly
show: false then ready-to-show — prevents white flash, looks more native
Native Module Pain
- Pre-built native modules won't work — must rebuild for Electron's specific Node version
electron-rebuild after every Electron upgrade — version mismatch = runtime crash- N-API modules more stable — survive Electron upgrades better than nan-based
Packaging Pitfalls
- Dev dependencies included by default — production builds bloat without explicit exclusion
- Code signing required for macOS auto-update — unsigned apps can't use Squirrel
- Windows notifications require
app.setAppUserModelId() — silent failure without it - ASAR isn't encryption — source readable with simple tools, don't rely on it for secrets
Platform-Specific Issues
- CORS blocks
file:// protocol — use custom protocol (app://) or local server - Windows needs NSIS or Squirrel for auto-update — installer format matters
- macOS universal binary needs
--universal flag — ships both Intel and ARM
Memory and Performance
- Unclosed windows leak memory — call
win.destroy() explicitly when done - Lazy load heavy modules — startup time directly affects perceived quality
backgroundThrottling: false if timers matter when minimized
Debugging
- Main process:
--inspect flag, connect via chrome://inspect - Renderer:
webContents.openDevTools() or keyboard shortcut electron-log for persistent logs — console.log vanishes on restart
版本历史
共 1 个版本
-
v1.0.0
当前
2026-03-28 22:58 安全 安全
安全检测
腾讯云安全 (Sanbu)
安全,无风险
查看报告
🔗 相关推荐
developer-tools
larsonreever
AI驱动平台,提供快速全栈开发、智能体、工作流自动化及低代码AI集成的可扩展产品创建。
★ 66
📥 179,998
ai-intelligence
ivangdavila
自我反思+自我批评+自我学习+自组织记忆。智能体评估自身工作、发现错误并持续改进。
★ 1,353
📥 317,940
developer-tools
steipete
Google Workspace 命令行工具,支持 Gmail、日历、云端硬盘、通讯录、表格和文档。
★ 921
📥 185,767