electron

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
Electron embeds Chromium and Node.js so you can ship one JavaScript codebase for Windows, macOS, and Linux. Use these skills when scaffolding projects, wiring main/renderer IPC, configuring security and packaging, or integrating native modules and auto-updates.
The skill is based on Electron (latest), generated at 2026-01-30.
Electron内置了Chromium和Node.js,因此你可以基于一套JavaScript代码库,发布适配Windows、macOS和Linux系统的应用。这些技能适用于项目搭建、主进程/渲染进程IPC通信配置、安全与打包设置、原生模块集成以及自动更新功能开发等场景。
本技能基于最新版Electron开发,生成时间为2026年1月30日。

Core References

核心参考

TopicDescriptionReference
Process ModelMain, renderer, preload, utility process; when to use eachcore-process-model
IPCRenderer↔main patterns (send, invoke, main→renderer), serializationcore-ipc
Context IsolationcontextBridge, exposing safe APIs from preloadcore-context-isolation
SandboxProcess sandboxing, preload polyfill, when it is disabledcore-sandbox
主题描述参考链接
进程模型主进程、渲染进程、预加载进程、实用工具进程;各进程的适用场景core-process-model
IPC通信渲染进程↔主进程的通信模式(send、invoke、主进程→渲染进程)、序列化处理core-ipc
上下文隔离contextBridge、从预加载进程暴露安全APIcore-context-isolation
沙箱机制进程沙箱、预加载兼容处理、沙箱禁用场景core-sandbox

Develop

开发指南

TopicDescriptionReference
AccessibilitysetAccessibilitySupportEnabled, assistive tech, AXManualAccessibilitydevelop-accessibility
App LifecyclewhenReady, window-all-closed, quit, single instance lockdevelop-app-lifecycle
BaseWindowMulti-view windows; contentView, View, addChildView; parent/modaldevelop-base-window
BrowserWindowCreating windows, loadURL/loadFile, ready-to-show, webPreferencesdevelop-browser-window
ClipboardreadText/writeText, readHTML/writeHTML; use from preloaddevelop-clipboard
Cookiessession.cookies; get, set, remove, flushStore; changed eventdevelop-cookies
Command Lineapp.commandLine, appendSwitch, hasSwitch; Electron/Node/Chromium flagsdevelop-command-line
Context MenuRight-click menu; webContents context-menu, Menu.popupdevelop-context-menu
contentTracingChromium tracing; startRecording, stopRecording; chrome://tracingdevelop-content-tracing
Crash ReportercrashReporter.start, submitURL, extra; call before readydevelop-crash-reporter
DebugRenderer DevTools, main process (--inspect, Chrome/VSCode)develop-debug
Debugger (CDP)webContents.debugger; attach, detach, sendCommand; DevTools Protocoldevelop-debugger
DevTools ExtensionloadExtension, removeExtension; electron-devtools-installerdevelop-devtools-extension
DialogshowOpenDialog, showSaveDialog, showMessageBox; expose via IPCdevelop-dialog
DockmacOS Dock; bounce, badge, icon, menu, hide/showdevelop-dock
Downloadswill-download, DownloadItem, setSavePath, preventDefaultdevelop-downloads
Keyboard ShortcutsAccelerators, local (MenuItem), global (globalShortcut)develop-keyboard-shortcuts
Linux Desktop Actions.desktop file Actions; launcher shortcuts; process.argvdevelop-linux-desktop-actions
Menus and TrayApplication/context/tray/dock menus; Tray icon and context menudevelop-menus-tray
Native ImagecreateFromPath, createFromBuffer, template image; tray, icondevelop-native-image
Native ModulesUsing native Node addons; @electron/rebuild, node-gypdevelop-native-modules
Netnet.fetch, net.request; HTTP from main (Chromium stack)develop-net
netLogSession network logging; startLogging, stopLogging, captureModedevelop-net-log
Drag and DropNative file drag out; webContents.startDrag, IPCdevelop-drag-drop
ESMES modules in main and preload; .mjs, caveatsdevelop-esm
MultithreadingWeb Workers, nodeIntegrationInWorker; no Electron in workersdevelop-multithreading
Navigation HistorywebContents.navigationHistory, goBack, goForward, getAllEntriesdevelop-navigation-history
Offscreen Renderingpaint event, NativeImage; GPU vs software; setFrameRatedevelop-offscreen-rendering
parentPortUtility process child; process.parentPort message/postMessagedevelop-parent-port
Power Monitorsuspend, resume, battery/AC, thermal-state-change, shutdowndevelop-power-monitor
Power Save BlockerpowerSaveBlocker; prevent display/app sleep; start/stop by iddevelop-power-save-blocker
Progress BarsetProgressBar (taskbar/dock); 0–1, indeterminatedevelop-progress-bar
ProtocolCustom protocol (protocol.handle), registerSchemesAsPrivilegeddevelop-protocol
Recent DocumentsaddRecentDocument, clearRecentDocuments; JumpList, Dockdevelop-recent-documents
Safe StorageencryptString, decryptString; OS keychaindevelop-safe-storage
ScreengetPrimaryDisplay, getAllDisplays, workAreaSize, display eventsdevelop-screen
Sessionpartition, defaultSession, permissionRequestHandler, cookiesdevelop-session
Share MenumacOS ShareMenu; share to apps/social; popup, shareMenu roledevelop-share-menu
ShellopenExternal, openPath, showItemInFolder, trashItem; securitydevelop-shell
Processprocess.type, process.versions, process.platform, process.masdevelop-process
Environment VariablesELECTRON_*, NODE_OPTIONS; fusesdevelop-environment-variables
Represented FilesetRepresentedFilename, setDocumentEdited (macOS title bar)develop-represented-file
System PreferencesgetEffectiveAppearance, getColor, getMediaAccessStatusdevelop-system-preferences
Touch BarmacOS TouchBar; items (Button, Label, Slider, etc.), setTouchBardevelop-touch-bar
TestsWebDriver/WebdriverIO E2E, headless CIdevelop-tests
Utility ProcessutilityProcess.fork, postMessage, MessagePortMaindevelop-utility-process
Web RequestonBeforeRequest, onHeadersReceived, filter; set CSPdevelop-web-request
webContents Navigationwill-navigate, setWindowOpenHandler, load eventsdevelop-webcontents-navigation
webFrameRenderer zoom, insertCSS, executeJavaScript, spell check, frame treedevelop-web-frame
webFrameMainMain process frame control; fromId/fromFrameToken, executeJavaScript, IPCdevelop-web-frame-main
webUtilsRenderer getPathForFile(File); file input path; expose via preloaddevelop-web-utils
Window CustomizationFrameless, transparent, custom title bardevelop-window-customization
Windows TaskbarJumpList, setThumbarButtons, setOverlayIcon, flashFramedevelop-windows-taskbar
主题描述参考链接
无障碍访问setAccessibilitySupportEnabled、辅助技术、AXManualAccessibilitydevelop-accessibility
应用生命周期whenReady、window-all-closed、quit、单实例锁develop-app-lifecycle
基础窗口多视图窗口;contentView、View、addChildView;父窗口/模态窗口develop-base-window
浏览器窗口创建窗口、loadURL/loadFile、ready-to-show、webPreferences配置develop-browser-window
剪贴板readText/writeText、readHTML/writeHTML;从预加载进程调用develop-clipboard
Cookiessession.cookies;获取、设置、删除、flushStore;changed事件develop-cookies
命令行app.commandLine、appendSwitch、hasSwitch;Electron/Node/Chromium参数develop-command-line
上下文菜单右键菜单;webContents context-menu、Menu.popupdevelop-context-menu
contentTracingChromium追踪;startRecording、stopRecording;chrome://tracingdevelop-content-tracing
崩溃上报crashReporter.start、submitURL、extra;需在ready前调用develop-crash-reporter
调试渲染进程DevTools、主进程调试(--inspect、Chrome/VSCode)develop-debug
调试器(CDP)webContents.debugger;attach、detach、sendCommand;DevTools协议develop-debugger
DevTools扩展loadExtension、removeExtension;electron-devtools-installerdevelop-devtools-extension
对话框showOpenDialog、showSaveDialog、showMessageBox;通过IPC暴露给渲染进程develop-dialog
Dock(macOS)macOS Dock;弹跳、徽章、图标、菜单、隐藏/显示develop-dock
下载管理will-download、DownloadItem、setSavePath、preventDefaultdevelop-downloads
键盘快捷键加速器、本地快捷键(MenuItem)、全局快捷键(globalShortcut)develop-keyboard-shortcuts
Linux桌面操作.desktop文件操作;启动器快捷方式;process.argvdevelop-linux-desktop-actions
菜单与托盘应用/上下文/托盘/Dock菜单;托盘图标与上下文菜单develop-menus-tray
原生图片createFromPath、createFromBuffer、模板图片;托盘、图标使用develop-native-image
原生模块使用Node原生扩展;@electron/rebuild、node-gypdevelop-native-modules
网络请求net.fetch、net.request;主进程发起HTTP请求(基于Chromium栈)develop-net
网络日志会话网络日志;startLogging、stopLogging、captureModedevelop-net-log
拖拽功能原生文件拖拽导出;webContents.startDrag、IPC通信develop-drag-drop
ESM模块主进程与预加载进程中的ES模块;.mjs、注意事项develop-esm
多线程Web Workers、nodeIntegrationInWorker;Worker中无法使用Electron APIdevelop-multithreading
导航历史webContents.navigationHistory、goBack、goForward、getAllEntriesdevelop-navigation-history
离屏渲染paint事件、NativeImage;GPU vs 软件渲染;setFrameRatedevelop-offscreen-rendering
parentPort实用工具进程子进程;process.parentPort message/postMessagedevelop-parent-port
电源监控suspend、resume、电池/AC供电、thermal-state-change、shutdowndevelop-power-monitor
电源休眠阻止powerSaveBlocker;阻止显示器/应用休眠;通过ID启动/停止develop-power-save-blocker
进度条setProgressBar(任务栏/Dock);0–1进度、不确定进度develop-progress-bar
自定义协议自定义协议(protocol.handle)、registerSchemesAsPrivilegeddevelop-protocol
最近文档addRecentDocument、clearRecentDocuments;JumpList、Dockdevelop-recent-documents
安全存储encryptString、decryptString;系统钥匙串develop-safe-storage
屏幕管理getPrimaryDisplay、getAllDisplays、workAreaSize、显示器事件develop-screen
会话管理partition、defaultSession、permissionRequestHandler、cookiesdevelop-session
分享菜单(macOS)macOS ShareMenu;分享到应用/社交平台;popup、shareMenu角色develop-share-menu
Shell操作openExternal、openPath、showItemInFolder、trashItem;安全注意事项develop-shell
进程信息process.type、process.versions、process.platform、process.masdevelop-process
环境变量ELECTRON_*、NODE_OPTIONS;fuses配置develop-environment-variables
关联文件setRepresentedFilename、setDocumentEdited(macOS标题栏)develop-represented-file
系统偏好设置getEffectiveAppearance、getColor、getMediaAccessStatusdevelop-system-preferences
Touch Bar(macOS)macOS TouchBar;组件(Button、Label、Slider等)、setTouchBardevelop-touch-bar
测试WebDriver/WebdriverIO端到端测试、无头CI环境develop-tests
实用工具进程utilityProcess.fork、postMessage、MessagePortMaindevelop-utility-process
Web请求onBeforeRequest、onHeadersReceived、filter;设置CSPdevelop-web-request
webContents导航will-navigate、setWindowOpenHandler、加载事件develop-webcontents-navigation
webFrame渲染进程缩放、insertCSS、executeJavaScript、拼写检查、框架树develop-web-frame
webFrameMain主进程框架控制;fromId/fromFrameToken、executeJavaScript、IPCdevelop-web-frame-main
webUtils渲染进程getPathForFile(File);文件输入路径;通过预加载进程暴露develop-web-utils
窗口自定义无边框窗口、透明窗口、自定义标题栏develop-window-customization
Windows任务栏JumpList、setThumbarButtons、setOverlayIcon、flashFramedevelop-windows-taskbar

Best Practices

最佳实践

TopicDescriptionReference
PerformanceMeasure first, defer loading, avoid blocking, bundlebest-practices-performance
SecurityContent loading, webPreferences, CSP, IPC validation, distributionbest-practices-security
VersioningSemVer, ~ vs ^, stabilization branches, upgrade and EOLbest-practices-versioning
主题描述参考链接
性能优化先测量性能、延迟加载、避免阻塞、代码打包best-practices-performance
安全配置内容加载、webPreferences、CSP、IPC验证、分发安全best-practices-security
版本管理语义化版本、~与^的区别、稳定分支、升级与生命周期结束(EOL)best-practices-versioning

Features

功能特性

TopicDescriptionReference
ASARPack/unpack, Node and Web API usage, unpack option, integrityfeatures-asar
Corner Smoothing-electron-corner-smoothing CSS; smooth rounded corners; system-uifeatures-corner-smoothing
Dark ModenativeTheme, themeSource, prefers-color-schemefeatures-dark-mode
Desktop CapturedesktopCapturer, setDisplayMediaRequestHandler, getDisplayMediafeatures-desktop-capture
FusesrunAsNode, nodeCliInspect, asar integrity; @electron/fusesfeatures-fuses
In-App PurchaseMac App Store IAP; purchaseProduct, getProducts, transactions-updatedfeatures-in-app-purchase
MessagePortsRenderer-to-renderer and main-renderer messaging; MessagePortMainfeatures-message-ports
NotificationsMain (Notification), renderer (Web Notifications API)features-notifications
Online/Offlinenet.isOnline(), net.online; navigator.onLine, online/offline eventsfeatures-online-offline
Push NotificationsAPNS (macOS); registerForAPNSNotifications, received-apns-notificationfeatures-push-notifications
Service Workerssession.serviceWorkers; getAllRunning, main↔SW IPC (IpcMainServiceWorker)features-service-workers
SpellcheckerEnable, setSpellCheckerLanguages, context menu, dictionary URLfeatures-spellchecker
UpdatesautoUpdater, Squirrel, publishing release metadatafeatures-updates
Web Embedsiframe, WebContentsView, webview tag; when to use eachfeatures-web-embeds
主题描述参考链接
ASAR打包打包/解包、Node与Web API使用、unpack选项、完整性校验features-asar
圆角平滑-electron-corner-smoothing CSS;平滑圆角;system-uifeatures-corner-smoothing
深色模式nativeTheme、themeSource、prefers-color-schemefeatures-dark-mode
桌面捕获desktopCapturer、setDisplayMediaRequestHandler、getDisplayMediafeatures-desktop-capture
Fuses配置runAsNode、nodeCliInspect、asar完整性;@electron/fusesfeatures-fuses
内购功能Mac App Store内购;purchaseProduct、getProducts、transactions-updatedfeatures-in-app-purchase
MessagePorts渲染进程间及主进程-渲染进程通信;MessagePortMainfeatures-message-ports
通知功能主进程(Notification)、渲染进程(Web Notifications API)features-notifications
在线/离线状态net.isOnline()、net.online;navigator.onLine、online/offline事件features-online-offline
推送通知APNS(macOS);registerForAPNSNotifications、received-apns-notificationfeatures-push-notifications
Service Workerssession.serviceWorkers;getAllRunning、主进程↔SW IPC(IpcMainServiceWorker)features-service-workers
拼写检查启用拼写检查、setSpellCheckerLanguages、上下文菜单、词典URLfeatures-spellchecker
自动更新autoUpdater、Squirrel、发布版本元数据features-updates
Web嵌入iframe、WebContentsView、webview标签;各方案的适用场景features-web-embeds

Distribute

分发部署

TopicDescriptionReference
Code SigningmacOS sign + notarize; Windows Authenticodedistribute-code-signing
Mac App StoreMAS build, Apple Distribution, sandbox, limitationsdistribute-mac-app-store
PackagingTooling (Forge), manual layout, asar, rebrandingdistribute-packaging
Windows StoreAppX/MSIX, electron-windows-store, process.windowsStoredistribute-windows-store
主题描述参考链接
代码签名macOS签名+公证;Windows Authenticode签名distribute-code-signing
Mac App StoreMAS构建、Apple Distribution、沙箱、限制条件distribute-mac-app-store
应用打包工具(Forge)、手动布局、asar、品牌定制distribute-packaging
Windows StoreAppX/MSIX、electron-windows-store、process.windowsStoredistribute-windows-store