Electron Knowledge Patch
Use this skill when writing, reviewing, or upgrading Electron applications. Check the
project's pinned Electron version first and apply guidance only when the relevant
change has shipped in that version. Treat the application manifest, lockfile, code,
and tests as authoritative when they disagree with this guidance.
Reference index
| Reference |
Topics |
| Upgrades and runtime |
Embedded runtimes, platform requirements, support windows, installation, and artifacts |
| Sessions, networking, and extensions |
Sessions, service workers, protocols, requests, storage, extensions, and WebAuthn |
| Processes, diagnostics, and runtime behavior |
Frames, utility processes, diagnostics, command-line handling, PDF, and process exits |
| Windows, input, and platform UI |
BrowserWindow, menus, shortcuts, dialogs, printing, navigation, and desktop integration |
| Graphics, media, and NativeImage |
Offscreen rendering, shared textures, capture, color management, and image APIs |
| Notifications, security, and packaging |
Notifications, clipboard isolation, ASAR integrity, safe storage, updates, and signing |
Upgrade triage
Prepare for removals
- Electron 44 removes the renderer
clipboard module. Prefer
navigator.clipboard, or expose narrowly scoped advanced operations from a
preload with contextBridge.
- Electron 44 requires macOS 13 or later and stops publishing 32-bit companion
artifacts. Electron 43 is the final prebuilt line for Windows x86 and Linux
ARMv7.
- Linux
showHiddenFiles was deprecated in Electron 41 and removed in Electron
- Do not rely on it outside macOS and Windows.
webContents no longer emits plugin-crashed.
PrinterInfo.isDefault and PrinterInfo.status are gone.
- Remove
systemPreferences.isAeroGlassEnabled() branches; the API has no
replacement.
Migrate deprecated APIs
- Replace
Session.setPreloads() and getPreloads() with
registerPreloadScript(), unregisterPreloadScript(), and
getPreloadScripts().
- Replace
session.serviceWorkers.fromVersionID() with
getInfoFromVersionID() or getWorkerFromVersionID().
- Move extension methods and events from
session to session.extensions.
- Replace
NativeImage.getBitmap() with toBitmap().
- Replace
webFrame.routingId and findFrameByRoutingId() with frameToken
and findFrameByToken(); resolve main-process tokens with
webFrameMain.fromFrameToken().
- Stop passing
quota or quotas to Session.clearStorageData().
- Read
console-message data from the event object and use lineNumber.
- Use
--host-resolver-rules instead of Chromium's deprecated --host-rules.
Audit changed defaults
- An empty web-request
urls array matches nothing; use ['<all_urls>'] when
every URL is intended.
- Electron runs natively on Wayland when available. Pass
--ozone-platform=x11 only when Xwayland behavior is required.
- Offscreen rendering uses device scale factor
1.0; set
webPreferences.offscreen.deviceScaleFactor explicitly for another scale.
window.open() popups are always resizable unless
setWindowOpenHandler() overrides resizable.
- Downloads and dialogs without
defaultPath start in Downloads, falling back
to Home. Persist and pass a directory to retain last-used behavior.
app.commandLine lowercases switches and arguments. Read application-specific
arguments from process.argv.
- A utility-process
process.exit() is synchronous, so buffered output may not
flush.
Security-critical behavior
Keep renderer privileges narrow
Direct renderer access to Electron's clipboard API is deprecated before its
removal. Put privileged work in the main or preload context and expose the
smallest possible surface:
const { clipboard, contextBridge } = require('electron');
contextBridge.exposeInMainWorld('clipboardAPI', {
readText: () => clipboard.readText(),
});
Sandboxed windows opened by a top-level frame inherit the opener's sandbox
restrictions. <webview> and window.open() also inherit
nodeIntegrationInWorker; do not assume a child silently resets security
preferences.
Package and sign correctly
- Stable ASAR integrity terminates the app when the packaged archive hash is
absent or mismatched. On macOS, embed the ASAR-integrity digest and re-sign.
- macOS notifications require a code-signed application; unsigned apps emit
failed instead of displaying the notification.
- Desktop capture with audio on macOS 14.2 or later needs
NSAudioCaptureUsageDescription or the CoreAudio Tap path can return silent
audio without an error.
allowExtensions: true is required when Chrome extensions must access a
privileged custom protocol.
High-value APIs
Diagnose hung and failed renderers
To collect a JavaScript stack from an unresponsive renderer, enable the feature
and serve the matching Document Policy header:
app.commandLine.appendSwitch(
'enable-features',
'DocumentPolicyIncludeJSCallStacksInCrashReports',
);
webContents.on('unresponsive', async () => {
console.log(await webContents.mainFrame.collectJavaScriptCallStack());
});
Use WebFrameMain.detached for unloading state and isDestroyed() for final
destruction. Heap tracing and renderer out-of-memory diagnostics can also capture
JavaScript evidence.
Register per-context preloads
Preload registrations can target either frame or service-worker. A service
worker preload uses ipcRenderer; communicate from the main process through
ServiceWorkerMain.ipc. Use startWorkerForScope() and
running-status-changed when lifecycle control is needed.
Filter requests explicitly
const filter = {
urls: ['<all_urls>'],
excludeUrls: ['https://example.test/private/*'],
};
Use net.request({ bypassCustomProtocolHandlers: true }) when a request must
skip registered protocol handlers. WebSocket authentication arrives through the
webContents login event.
Control popups and navigation
webContents.setWindowOpenHandler((details) => ({
action: 'allow',
overrideBrowserWindowOptions: {
resizable: details.features.includes('resizable=yes'),
},
}));
Set webPreferences.focusOnNavigation to false when navigation must not focus
the WebContents. Restore captured history with
webContents.navigationHistory.restore(index, entries).
Render frames to PDF
Patch releases add per-frame PDF output:
const frame = browserWindow.webContents.mainFrame;
const pdf = await frame.printToPDF({});
PDF resources render inside the existing WebContents, so detection should
inspect the frame tree rather than wait for a guest WebContents.
Work with notifications
- On Windows, use
Notification.handleActivation() for clicks, replies, and
actions that can cold-start the app.
- Use notification IDs and group IDs for grouping; macOS also exposes history
and removal APIs.
- Windows notification actions support buttons, selects, and replies, while the
closed event reports a dismissal reason.
Handle graphics predictably
- Shared-texture
paint payload fields live beneath handle.
- Imported textures support NV12, NV16, and P010LE; external textures can become
VideoFrame objects.
NativeImage normalizes profiled input to sRGB. Pass a colorSpace option to
toBitmap() when source-space output or another conversion is required.
- Use an options object for
createFromNamedImage(name, { hslShift }); the
positional HSL array is deprecated.
Platform checks
macOS
- Pass
WebContents.focusedFrame to Menu.popup({ frame }) for Writing Tools,
Autofill, and Services integration.
- Use
nativeTheme.shouldUseDarkColorsForSystemIntegratedUI for system UI and
shouldDifferentiateWithoutColor for the accessibility preference.
- Configure Touch ID WebAuthn through
app.configureWebAuthn() and handle
discoverable-account selection on the session.
Linux
- GTK 4 is the GNOME default. Force GTK 3 before startup when native dependencies
cannot coexist with GTK 4.
- Frameless windows have rounded corners; disable with
roundedCorners: false.
- Window Controls Overlay follows the native title-bar button layout. Position
content with
env(titlebar-area-x) and env(titlebar-area-width).
- Portal file-dialog backends older than version 4 ignore
defaultPath; require
portal version 4 when that option is essential.
Windows
- Fullscreen hides the menu bar.
query-session-end supports pre-shutdown handling, alongside improved
session-end behavior.
roundedCorners is supported, and MSIX applications can use autoUpdater.
Verification checklist
- Confirm the pinned Electron version and supported operating systems.
- Search for removed and deprecated APIs before changing dependencies.
- Test renderer sandbox, preload, protocol, and child-window inheritance.
- Exercise Wayland/X11, GTK, macOS signing, and Windows packaging paths used by
the application.
- Re-test offscreen scale, image color, media capture, dialogs, notifications,
printing, and PDF behavior where applicable.
- Inspect process-exit reasons and utility-process logs under failure.
1---2name: electron-knowledge-patch-23description: Electron4license: MIT5---678# Electron Knowledge Patch910Use this skill when writing, reviewing, or upgrading Electron applications. Check the11project's pinned Electron version first and apply guidance only when the relevant12change has shipped in that version. Treat the application manifest, lockfile, code,13and tests as authoritative when they disagree with this guidance.1415## Reference index1617| Reference | Topics |18| --- | --- |19| [Upgrades and runtime](references/upgrades-and-runtime.md) | Embedded runtimes, platform requirements, support windows, installation, and artifacts |20| [Sessions, networking, and extensions](references/sessions-networking-and-extensions.md) | Sessions, service workers, protocols, requests, storage, extensions, and WebAuthn |21| [Processes, diagnostics, and runtime behavior](references/processes-diagnostics-and-runtime.md) | Frames, utility processes, diagnostics, command-line handling, PDF, and process exits |22| [Windows, input, and platform UI](references/windows-input-and-platform-ui.md) | BrowserWindow, menus, shortcuts, dialogs, printing, navigation, and desktop integration |23| [Graphics, media, and NativeImage](references/graphics-media-and-native-image.md) | Offscreen rendering, shared textures, capture, color management, and image APIs |24| [Notifications, security, and packaging](references/notifications-security-and-packaging.md) | Notifications, clipboard isolation, ASAR integrity, safe storage, updates, and signing |2526## Upgrade triage2728### Prepare for removals2930- Electron 44 removes the renderer `clipboard` module. Prefer31 `navigator.clipboard`, or expose narrowly scoped advanced operations from a32 preload with `contextBridge`.33- Electron 44 requires macOS 13 or later and stops publishing 32-bit companion34 artifacts. Electron 43 is the final prebuilt line for Windows x86 and Linux35 ARMv7.36- Linux `showHiddenFiles` was deprecated in Electron 41 and removed in Electron37 43. Do not rely on it outside macOS and Windows.38- `webContents` no longer emits `plugin-crashed`.39- `PrinterInfo.isDefault` and `PrinterInfo.status` are gone.40- Remove `systemPreferences.isAeroGlassEnabled()` branches; the API has no41 replacement.4243### Migrate deprecated APIs4445- Replace `Session.setPreloads()` and `getPreloads()` with46 `registerPreloadScript()`, `unregisterPreloadScript()`, and47 `getPreloadScripts()`.48- Replace `session.serviceWorkers.fromVersionID()` with49 `getInfoFromVersionID()` or `getWorkerFromVersionID()`.50- Move extension methods and events from `session` to `session.extensions`.51- Replace `NativeImage.getBitmap()` with `toBitmap()`.52- Replace `webFrame.routingId` and `findFrameByRoutingId()` with `frameToken`53 and `findFrameByToken()`; resolve main-process tokens with54 `webFrameMain.fromFrameToken()`.55- Stop passing `quota` or `quotas` to `Session.clearStorageData()`.56- Read `console-message` data from the event object and use `lineNumber`.57- Use `--host-resolver-rules` instead of Chromium's deprecated `--host-rules`.5859### Audit changed defaults6061- An empty web-request `urls` array matches nothing; use `['<all_urls>']` when62 every URL is intended.63- Electron runs natively on Wayland when available. Pass64 `--ozone-platform=x11` only when Xwayland behavior is required.65- Offscreen rendering uses device scale factor `1.0`; set66 `webPreferences.offscreen.deviceScaleFactor` explicitly for another scale.67- `window.open()` popups are always resizable unless68 `setWindowOpenHandler()` overrides `resizable`.69- Downloads and dialogs without `defaultPath` start in Downloads, falling back70 to Home. Persist and pass a directory to retain last-used behavior.71- `app.commandLine` lowercases switches and arguments. Read application-specific72 arguments from `process.argv`.73- A utility-process `process.exit()` is synchronous, so buffered output may not74 flush.7576## Security-critical behavior7778### Keep renderer privileges narrow7980Direct renderer access to Electron's clipboard API is deprecated before its81removal. Put privileged work in the main or preload context and expose the82smallest possible surface:8384```js85const { clipboard, contextBridge } = require('electron');8687contextBridge.exposeInMainWorld('clipboardAPI', {88 readText: () => clipboard.readText(),89});90```9192Sandboxed windows opened by a top-level frame inherit the opener's sandbox93restrictions. `<webview>` and `window.open()` also inherit94`nodeIntegrationInWorker`; do not assume a child silently resets security95preferences.9697### Package and sign correctly9899- Stable ASAR integrity terminates the app when the packaged archive hash is100 absent or mismatched. On macOS, embed the ASAR-integrity digest and re-sign.101- macOS notifications require a code-signed application; unsigned apps emit102 `failed` instead of displaying the notification.103- Desktop capture with audio on macOS 14.2 or later needs104 `NSAudioCaptureUsageDescription` or the CoreAudio Tap path can return silent105 audio without an error.106- `allowExtensions: true` is required when Chrome extensions must access a107 privileged custom protocol.108109## High-value APIs110111### Diagnose hung and failed renderers112113To collect a JavaScript stack from an unresponsive renderer, enable the feature114and serve the matching Document Policy header:115116```js117app.commandLine.appendSwitch(118 'enable-features',119 'DocumentPolicyIncludeJSCallStacksInCrashReports',120);121122webContents.on('unresponsive', async () => {123 console.log(await webContents.mainFrame.collectJavaScriptCallStack());124});125```126127Use `WebFrameMain.detached` for unloading state and `isDestroyed()` for final128destruction. Heap tracing and renderer out-of-memory diagnostics can also capture129JavaScript evidence.130131### Register per-context preloads132133Preload registrations can target either `frame` or `service-worker`. A service134worker preload uses `ipcRenderer`; communicate from the main process through135`ServiceWorkerMain.ipc`. Use `startWorkerForScope()` and136`running-status-changed` when lifecycle control is needed.137138### Filter requests explicitly139140```js141const filter = {142 urls: ['<all_urls>'],143 excludeUrls: ['https://example.test/private/*'],144};145```146147Use `net.request({ bypassCustomProtocolHandlers: true })` when a request must148skip registered protocol handlers. WebSocket authentication arrives through the149`webContents` `login` event.150151### Control popups and navigation152153```js154webContents.setWindowOpenHandler((details) => ({155 action: 'allow',156 overrideBrowserWindowOptions: {157 resizable: details.features.includes('resizable=yes'),158 },159}));160```161162Set `webPreferences.focusOnNavigation` to `false` when navigation must not focus163the `WebContents`. Restore captured history with164`webContents.navigationHistory.restore(index, entries)`.165166### Render frames to PDF167168Patch releases add per-frame PDF output:169170```js171const frame = browserWindow.webContents.mainFrame;172const pdf = await frame.printToPDF({});173```174175PDF resources render inside the existing `WebContents`, so detection should176inspect the frame tree rather than wait for a guest `WebContents`.177178### Work with notifications179180- On Windows, use `Notification.handleActivation()` for clicks, replies, and181 actions that can cold-start the app.182- Use notification IDs and group IDs for grouping; macOS also exposes history183 and removal APIs.184- Windows notification actions support buttons, selects, and replies, while the185 `closed` event reports a dismissal `reason`.186187### Handle graphics predictably188189- Shared-texture `paint` payload fields live beneath `handle`.190- Imported textures support NV12, NV16, and P010LE; external textures can become191 `VideoFrame` objects.192- `NativeImage` normalizes profiled input to sRGB. Pass a `colorSpace` option to193 `toBitmap()` when source-space output or another conversion is required.194- Use an options object for `createFromNamedImage(name, { hslShift })`; the195 positional HSL array is deprecated.196197## Platform checks198199### macOS200201- Pass `WebContents.focusedFrame` to `Menu.popup({ frame })` for Writing Tools,202 Autofill, and Services integration.203- Use `nativeTheme.shouldUseDarkColorsForSystemIntegratedUI` for system UI and204 `shouldDifferentiateWithoutColor` for the accessibility preference.205- Configure Touch ID WebAuthn through `app.configureWebAuthn()` and handle206 discoverable-account selection on the session.207208### Linux209210- GTK 4 is the GNOME default. Force GTK 3 before startup when native dependencies211 cannot coexist with GTK 4.212- Frameless windows have rounded corners; disable with `roundedCorners: false`.213- Window Controls Overlay follows the native title-bar button layout. Position214 content with `env(titlebar-area-x)` and `env(titlebar-area-width)`.215- Portal file-dialog backends older than version 4 ignore `defaultPath`; require216 portal version 4 when that option is essential.217218### Windows219220- Fullscreen hides the menu bar.221- `query-session-end` supports pre-shutdown handling, alongside improved222 `session-end` behavior.223- `roundedCorners` is supported, and MSIX applications can use `autoUpdater`.224225## Verification checklist2262271. Confirm the pinned Electron version and supported operating systems.2282. Search for removed and deprecated APIs before changing dependencies.2293. Test renderer sandbox, preload, protocol, and child-window inheritance.2304. Exercise Wayland/X11, GTK, macOS signing, and Windows packaging paths used by231 the application.2325. Re-test offscreen scale, image color, media capture, dialogs, notifications,233 printing, and PDF behavior where applicable.2346. Inspect process-exit reasons and utility-process logs under failure.