From 4dbeabb17e9cad02424d884c29da8bde85b3f01a Mon Sep 17 00:00:00 2001 From: "electron-website-docs-updater[bot]" <166660481+electron-website-docs-updater[bot]@users.noreply.github.com> Date: Tue, 28 Oct 2025 20:03:59 +0000 Subject: [PATCH 1/2] =?UTF-8?q?chore:=20update=20ref=20to=20docs=20(?= =?UTF-8?q?=F0=9F=A4=96)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/latest/.sha | 2 +- docs/latest/api/app.md | 1 + docs/latest/api/command-line-switches.md | 34 ++- docs/latest/api/context-bridge.md | 1 + docs/latest/api/desktop-capturer.md | 4 + docs/latest/api/structures/color-space.md | 202 ++++++++++++++++++ .../structures/offscreen-shared-texture.md | 19 +- .../structures/render-process-gone-details.md | 1 + .../api/structures/shared-texture-handle.md | 19 ++ docs/latest/api/structures/usb-device.md | 40 +++- docs/latest/api/structures/web-preferences.md | 5 + docs/latest/api/system-preferences.md | 4 +- docs/latest/breaking-changes.md | 31 +++ docs/latest/glossary.md | 9 + docs/latest/tutorial/asar-integrity.md | 4 +- docs/latest/tutorial/automated-testing.md | 72 +++---- docs/latest/tutorial/electron-timelines.md | 2 +- docs/latest/tutorial/fuses.md | 113 +++++++--- docs/latest/tutorial/online-offline-events.md | 38 +++- docs/latest/tutorial/security.md | 6 +- 20 files changed, 490 insertions(+), 117 deletions(-) create mode 100644 docs/latest/api/structures/color-space.md create mode 100644 docs/latest/api/structures/shared-texture-handle.md diff --git a/docs/latest/.sha b/docs/latest/.sha index 64ae02882..f49f064b2 100644 --- a/docs/latest/.sha +++ b/docs/latest/.sha @@ -1 +1 @@ -370a737ced00938da0a8140d894abaf23bbb6256 \ No newline at end of file +429b5376cbe31dc55a4318d2f73b3cbb05dd680a \ No newline at end of file diff --git a/docs/latest/api/app.md b/docs/latest/api/app.md index 733b236f0..5f5d09f0d 100644 --- a/docs/latest/api/app.md +++ b/docs/latest/api/app.md @@ -428,6 +428,7 @@ Returns: * `oom` - Process ran out of memory * `launch-failed` - Process never successfully launched * `integrity-failure` - Windows code integrity checks failed + * `memory-eviction` - Process proactively terminated to prevent a future out-of-memory (OOM) situation * `exitCode` number - The exit code for the process (e.g. status from waitpid if on POSIX, from GetExitCodeProcess on Windows). * `serviceName` string (optional) - The non-localized name of the process. diff --git a/docs/latest/api/command-line-switches.md b/docs/latest/api/command-line-switches.md index 378f9c78c..d39084163 100644 --- a/docs/latest/api/command-line-switches.md +++ b/docs/latest/api/command-line-switches.md @@ -93,7 +93,7 @@ Field trials to be forcefully enabled or disabled. For example: `WebRTC-Audio-Red-For-Opus/Enabled/` -### --host-rules=`rules` +### --host-rules=`rules` _Deprecated_ A comma-separated list of `rules` that control how hostnames are mapped. @@ -111,9 +111,23 @@ These mappings apply to the endpoint host in a net request (the TCP connect and host resolver in a direct connection, and the `CONNECT` in an HTTP proxy connection, and the endpoint host in a `SOCKS` proxy connection). +**Deprecated:** Use the `--host-resolver-rules` switch instead. + ### --host-resolver-rules=`rules` -Like `--host-rules` but these `rules` only apply to the host resolver. +A comma-separated list of `rules` that control how hostnames are mapped. + +For example: + +* `MAP * 127.0.0.1` Forces all hostnames to be mapped to 127.0.0.1 +* `MAP *.google.com proxy` Forces all google.com subdomains to be resolved to + "proxy". +* `MAP test.com [::1]:77` Forces "test.com" to resolve to IPv6 loopback. Will + also force the port of the resulting socket address to be 77. +* `MAP * baz, EXCLUDE www.google.com` Remaps everything to "baz", except for + "www.google.com". + +These `rules` only apply to the host resolver. ### --ignore-certificate-errors @@ -338,6 +352,22 @@ Affects the default output directory of [v8.setHeapSnapshotNearHeapLimit](https: Disable exposition of [Navigator API][] on the global scope from Node.js. +## Chromium Flags + +There isn't a documented list of all Chromium switches, but there are a few ways to find them. + +The easiest way is through Chromium's flags page, which you can access at `about://flags`. These flags don't directly match switch names, but they show up in the process's command-line arguments. + +To see these arguments, enable a flag in `about://flags`, then go to `about://version` in Chromium. You'll find a list of command-line arguments, including `--flag-switches-begin --your --list --flag-switches-end`, which contains the list of your flag enabled switches. + +Most flags are included as part of `--enable-features=`, but some are standalone switches, like `--enable-experimental-web-platform-features`. + +A complete list of flags exists in [Chromium's flag metadata page](https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/flag-metadata.json), but this list includes platform, environment and GPU specific, expired and potentially non-functional flags, so many of them might not always work in every situation. + +Keep in mind that standalone switches can sometimes be split into individual features, so there's no fully complete list of switches. + +Finally, you'll need to ensure that the version of Chromium in Electron matches the version of the browser you're using to cross-reference the switches. + [app]: app.md [append-switch]: command-line.md#commandlineappendswitchswitch-value [debugging-main-process]: ../tutorial/debugging-main-process.md diff --git a/docs/latest/api/context-bridge.md b/docs/latest/api/context-bridge.md index 386eece7c..221fc1a61 100644 --- a/docs/latest/api/context-bridge.md +++ b/docs/latest/api/context-bridge.md @@ -162,6 +162,7 @@ has been included below for completeness: | [Cloneable Types](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm) | Simple | ✅ | ✅ | See the linked document on cloneable types | | `Element` | Complex | ✅ | ✅ | Prototype modifications are dropped. Sending custom elements will not work. | | `Blob` | Complex | ✅ | ✅ | N/A | +| `VideoFrame` | Complex | ✅ | ✅ | N/A | | `Symbol` | N/A | ❌ | ❌ | Symbols cannot be copied across contexts so they are dropped | If the type you care about is not in the above table, it is probably not supported. diff --git a/docs/latest/api/desktop-capturer.md b/docs/latest/api/desktop-capturer.md index ef259ef8c..cbf7f79f6 100644 --- a/docs/latest/api/desktop-capturer.md +++ b/docs/latest/api/desktop-capturer.md @@ -109,6 +109,10 @@ Returns `Promise` - Resolves with an array of [`Desktop ## Caveats +`desktopCapturer.getSources(options)` only returns a single source on Linux when using Pipewire. + +PipeWire supports a single capture for both screens and windows. If you request the window and screen type, the selected source will be returned as a window capture. + `navigator.mediaDevices.getUserMedia` does not work on macOS for audio capture due to a fundamental limitation whereby apps that want to access the system's audio require a [signed kernel extension](https://developer.apple.com/library/archive/documentation/Security/Conceptual/System_Integrity_Protection_Guide/KernelExtensions/KernelExtensions.html). Chromium, and by extension Electron, does not provide this. It is possible to circumvent this limitation by capturing system audio with another macOS app like Soundflower and passing it through a virtual audio input device. This virtual device can then be queried with `navigator.mediaDevices.getUserMedia`. diff --git a/docs/latest/api/structures/color-space.md b/docs/latest/api/structures/color-space.md new file mode 100644 index 000000000..bd50ff0f6 --- /dev/null +++ b/docs/latest/api/structures/color-space.md @@ -0,0 +1,202 @@ +--- +title: "ColorSpace Object" +description: "" +slug: color-space +hide_title: false +--- + +# ColorSpace Object + +* `primaries` string - The color primaries of the color space. Can be one of the following values: + * `bt709` - BT709 primaries (also used for sRGB) + * `bt470m` - BT470M primaries + * `bt470bg` - BT470BG primaries + * `smpte170m` - SMPTE170M primaries + * `smpte240m` - SMPTE240M primaries + * `film` - Film primaries + * `bt2020` - BT2020 primaries + * `smptest428-1` - SMPTEST428-1 primaries + * `smptest431-2` - SMPTEST431-2 primaries + * `p3` - P3 primaries + * `xyz-d50` - XYZ D50 primaries + * `adobe-rgb` - Adobe RGB primaries + * `apple-generic-rgb` - Apple Generic RGB primaries + * `wide-gamut-color-spin` - Wide Gamut Color Spin primaries + * `ebu-3213-e` - EBU 3213-E primaries + * `custom` - Custom primaries + * `invalid` - Invalid primaries + +* `transfer` string - The transfer function of the color space. Can be one of the following values: + * `bt709` - BT709 transfer function + * `bt709-apple` - BT709 Apple transfer function + * `gamma18` - Gamma 1.8 transfer function + * `gamma22` - Gamma 2.2 transfer function + * `gamma24` - Gamma 2.4 transfer function + * `gamma28` - Gamma 2.8 transfer function + * `smpte170m` - SMPTE170M transfer function + * `smpte240m` - SMPTE240M transfer function + * `linear` - Linear transfer function + * `log` - Log transfer function + * `log-sqrt` - Log Square Root transfer function + * `iec61966-2-4` - IEC61966-2-4 transfer function + * `bt1361-ecg` - BT1361 ECG transfer function + * `srgb` - sRGB transfer function + * `bt2020-10` - BT2020-10 transfer function + * `bt2020-12` - BT2020-12 transfer function + * `pq` - PQ (Perceptual Quantizer) transfer function + * `smptest428-1` - SMPTEST428-1 transfer function + * `hlg` - HLG (Hybrid Log-Gamma) transfer function + * `srgb-hdr` - sRGB HDR transfer function + * `linear-hdr` - Linear HDR transfer function + * `custom` - Custom transfer function + * `custom-hdr` - Custom HDR transfer function + * `scrgb-linear-80-nits` - scRGB Linear 80 nits transfer function + * `invalid` - Invalid transfer function + +* `matrix` string - The color matrix of the color space. Can be one of the following values: + * `rgb` - RGB matrix + * `bt709` - BT709 matrix + * `fcc` - FCC matrix + * `bt470bg` - BT470BG matrix + * `smpte170m` - SMPTE170M matrix + * `smpte240m` - SMPTE240M matrix + * `ycocg` - YCoCg matrix + * `bt2020-ncl` - BT2020 NCL matrix + * `ydzdx` - YDzDx matrix + * `gbr` - GBR matrix + * `invalid` - Invalid matrix + +* `range` string - The color range of the color space. Can be one of the following values: + * `limited` - Limited color range (RGB values ranging from 16 to 235) + * `full` - Full color range (RGB values from 0 to 255) + * `derived` - Range defined by the transfer function and matrix + * `invalid` - Invalid range + +## Common `ColorSpace` definitions + +### Standard Color Spaces + +**sRGB**: + + ```js + const cs = { + primaries: 'bt709', + transfer: 'srgb', + matrix: 'rgb', + range: 'full' + } + ``` + +**Display P3**: + + ```js + const cs = { + primaries: 'p3', + transfer: 'srgb', + matrix: 'rgb', + range: 'full' + } + ``` + +**XYZ D50**: + + ```js + const cs = { + primaries: 'xyz-d50', + transfer: 'linear', + matrix: 'rgb', + range: 'full' + } + ``` + +### HDR Color Spaces + +**Extended sRGB** (extends sRGB to all real values): + + ```js + const cs = { + primaries: 'bt709', + transfer: 'srgb-hdr', + matrix: 'rgb', + range: 'full' + } + ``` + +**scRGB Linear** (linear transfer function for all real values): + + ```js + const cs = { + primaries: 'bt709', + transfer: 'linear-hdr', + matrix: 'rgb', + range: 'full' + } + ``` + +**scRGB Linear 80 Nits** (with an SDR white level of 80 nits): + + ```js + const cs = { + primaries: 'bt709', + transfer: 'scrgb-linear-80-nits', + matrix: 'rgb', + range: 'full' + } + ``` + +**HDR10** (BT.2020 primaries with PQ transfer function): + + ```js + const cs = { + primaries: 'bt2020', + transfer: 'pq', + matrix: 'rgb', + range: 'full' + } + ``` + +**HLG** (BT.2020 primaries with HLG transfer function): + + ```js + const cs = { + primaries: 'bt2020', + transfer: 'hlg', + matrix: 'rgb', + range: 'full' + } + ``` + +### Video Color Spaces + +**Rec. 601** (SDTV): + + ```js + const cs = { + primaries: 'smpte170m', + transfer: 'smpte170m', + matrix: 'smpte170m', + range: 'limited' + } + ``` + +**Rec. 709** (HDTV): + + ```js + const cs = { + primaries: 'bt709', + transfer: 'bt709', + matrix: 'bt709', + range: 'limited' + } + ``` + +**JPEG** (typical color space for JPEG images): + + ```js + const cs = { + primaries: 'bt709', + transfer: 'srgb', + matrix: 'smpte170m', + range: 'full' + } + ``` diff --git a/docs/latest/api/structures/offscreen-shared-texture.md b/docs/latest/api/structures/offscreen-shared-texture.md index d289040c0..f33a5a0ba 100644 --- a/docs/latest/api/structures/offscreen-shared-texture.md +++ b/docs/latest/api/structures/offscreen-shared-texture.md @@ -9,9 +9,13 @@ hide_title: false * `textureInfo` Object - The shared texture info. * `widgetType` string - The widget type of the texture. Can be `popup` or `frame`. - * `pixelFormat` string - The pixel format of the texture. Can be `rgba` or `bgra`. + * `pixelFormat` string - The pixel format of the texture. + * `rgba` - The texture format is 8-bit unorm RGBA. + * `bgra` - The texture format is 8-bit unorm BGRA. + * `rgbaf16` - The texture format is 16-bit float RGBA. * `codedSize` [Size](size.md) - The full dimensions of the video frame. - * `visibleRect` [Rectangle](rectangle.md) - A subsection of [0, 0, codedSize.width(), codedSize.height()]. In OSR case, it is expected to have the full section area. + * `colorSpace` [ColorSpace](color-space.md) - The color space of the video frame. + * `visibleRect` [Rectangle](rectangle.md) - A subsection of [0, 0, codedSize.width, codedSize.height]. In OSR case, it is expected to have the full section area. * `contentRect` [Rectangle](rectangle.md) - The region of the video frame that capturer would like to populate. In OSR case, it is the same with `dirtyRect` that needs to be painted. * `timestamp` number - The time in microseconds since the capture start. * `metadata` Object - Extra metadata. See comments in src\media\base\video_frame_metadata.h for accurate details. @@ -19,13 +23,6 @@ hide_title: false * `regionCaptureRect` [Rectangle](rectangle.md) (optional) - May reflect the frame's contents origin if region capture is used internally. * `sourceSize` [Rectangle](rectangle.md) (optional) - Full size of the source frame. * `frameCount` number (optional) - The increasing count of captured frame. May contain gaps if frames are dropped between two consecutively received frames. - * `sharedTextureHandle` Buffer _Windows_ _macOS_ - The handle to the shared texture. - * `planes` Object[] _Linux_ - Each plane's info of the shared texture. - * `stride` number - The strides and offsets in bytes to be used when accessing the buffers via a memory mapping. One per plane per entry. - * `offset` number - The strides and offsets in bytes to be used when accessing the buffers via a memory mapping. One per plane per entry. - * `size` number - Size in bytes of the plane. This is necessary to map the buffers. - * `fd` number - File descriptor for the underlying memory object (usually dmabuf). - * `modifier` string _Linux_ - The modifier is retrieved from GBM library and passed to EGL driver. + * `handle` [SharedTextureHandle](shared-texture-handle.md) - The shared texture handle data. * `release` Function - Release the resources. The `texture` cannot be directly passed to another process, users need to maintain texture lifecycles in - main process, but it is safe to pass the `textureInfo` to another process. Only a limited number of textures can exist at the same time, so it's important - that you call `texture.release()` as soon as you're done with the texture. + main process, but it is safe to pass the `textureInfo` to another process. Only a limited number of textures can exist at the same time, so it's important that you call `texture.release()` as soon as you're done with the texture. diff --git a/docs/latest/api/structures/render-process-gone-details.md b/docs/latest/api/structures/render-process-gone-details.md index 8b28f4dfd..0143c6a6a 100644 --- a/docs/latest/api/structures/render-process-gone-details.md +++ b/docs/latest/api/structures/render-process-gone-details.md @@ -15,6 +15,7 @@ hide_title: false * `oom` - Process ran out of memory * `launch-failed` - Process never successfully launched * `integrity-failure` - Windows code integrity checks failed + * `memory-eviction` - Process proactively terminated to prevent a future out-of-memory (OOM) situation * `exitCode` Integer - The exit code of the process, unless `reason` is `launch-failed`, in which case `exitCode` will be a platform-specific launch failure error code. diff --git a/docs/latest/api/structures/shared-texture-handle.md b/docs/latest/api/structures/shared-texture-handle.md new file mode 100644 index 000000000..443c0b606 --- /dev/null +++ b/docs/latest/api/structures/shared-texture-handle.md @@ -0,0 +1,19 @@ +--- +title: "SharedTextureHandle Object" +description: "" +slug: shared-texture-handle +hide_title: false +--- + +# SharedTextureHandle Object + +* `ntHandle` Buffer (optional) _Windows_ - NT HANDLE holds the shared texture. Note that this NT HANDLE is local to current process. +* `ioSurface` Buffer (optional) _macOS_ - IOSurfaceRef holds the shared texture. Note that this IOSurface is local to current process (not global). +* `nativePixmap` Object (optional) _Linux_ - Structure contains planes of shared texture. + * `planes` Object[] _Linux_ - Each plane's info of the shared texture. + * `stride` number - The strides and offsets in bytes to be used when accessing the buffers via a memory mapping. One per plane per entry. + * `offset` number - The strides and offsets in bytes to be used when accessing the buffers via a memory mapping. One per plane per entry. + * `size` number - Size in bytes of the plane. This is necessary to map the buffers. + * `fd` number - File descriptor for the underlying memory object (usually dmabuf). + * `modifier` string _Linux_ - The modifier is retrieved from GBM library and passed to EGL driver. + * `supportsZeroCopyWebGpuImport` boolean _Linux_ - Indicates whether supports zero copy import to WebGPU. diff --git a/docs/latest/api/structures/usb-device.md b/docs/latest/api/structures/usb-device.md index 704d2515b..cbb751b0b 100644 --- a/docs/latest/api/structures/usb-device.md +++ b/docs/latest/api/structures/usb-device.md @@ -7,18 +7,36 @@ hide_title: false # USBDevice Object +* `configuration` Object (optional) - A [USBConfiguration](https://developer.mozilla.org/en-US/docs/Web/API/USBConfiguration) object containing information about the currently selected configuration of a USB device. + * `configurationValue` Integer - the configuration value of this configuration. + * `configurationName` string - the name provided by the device to describe this configuration. + * `interfaces` Object[] - An array of [USBInterface](https://developer.mozilla.org/en-US/docs/Web/API/USBInterface) objects containing information about an interface provided by the USB device. + * `interfaceNumber` Integer - the interface number of this interface. + * `alternate` Object - the currently selected alternative configuration of this interface. + * `alternateSetting` Integer - the alternate setting number of this interface. + * `interfaceClass` Integer - the class of this interface. See [USB.org](https://www.usb.org/defined-class-codes) for class code descriptions. + * `interfaceSubclass` Integer - the subclass of this interface. + * `interfaceProtocol` Integer - the protocol supported by this interface. + * `interfaceName` string (optional) - the name of the interface, if one is provided by the device. + * `endpoints` Object[] - an array containing instances of the [USBEndpoint interface](https://developer.mozilla.org/en-US/docs/Web/API/USBEndpoint) describing each of the endpoints that are part of this interface. + * `endpointNumber` Integer - this endpoint's "endpoint number" which is a value from 1 to 15. + * `direction` string - the direction in which this endpoint transfers data - can be either 'in' or 'out'. + * `type` string - the type of this endpoint - can be either 'bulk', 'interrupt', or 'isochronous'. + * `packetSize` Integer - the size of the packets that data sent through this endpoint will be divided into. + * `alternates` Object[] - an array containing instances of the [USBAlternateInterface](https://developer.mozilla.org/en-US/docs/Web/API/USBAlternateInterface) interface describing each of the alternative configurations possible for this interface. +* `configurations` Object[] - An array of [USBConfiguration](https://developer.mozilla.org/en-US/docs/Web/API/USBConfiguration) interfaces for controlling a paired USB device. +* `deviceClass` Integer - The device class for the communication interface supported by the device. * `deviceId` string - Unique identifier for the device. -* `vendorId` Integer - The USB vendor ID. -* `productId` Integer - The USB product ID. -* `productName` string (optional) - Name of the device. -* `serialNumber` string (optional) - The USB device serial number. -* `manufacturerName` string (optional) - The manufacturer name of the device. -* `usbVersionMajor` Integer - The USB protocol major version supported by the device -* `usbVersionMinor` Integer - The USB protocol minor version supported by the device -* `usbVersionSubminor` Integer - The USB protocol subminor version supported by the device -* `deviceClass` Integer - The device class for the communication interface supported by the device -* `deviceSubclass` Integer - The device subclass for the communication interface supported by the device -* `deviceProtocol` Integer - The device protocol for the communication interface supported by the device +* `deviceProtocol` Integer - The device protocol for the communication interface supported by the device. +* `deviceSubclass` Integer - The device subclass for the communication interface supported by the device. * `deviceVersionMajor` Integer - The major version number of the device as defined by the device manufacturer. * `deviceVersionMinor` Integer - The minor version number of the device as defined by the device manufacturer. * `deviceVersionSubminor` Integer - The subminor version number of the device as defined by the device manufacturer. +* `manufacturerName` string (optional) - The manufacturer name of the device. +* `productId` Integer - The USB product ID. +* `productName` string (optional) - Name of the device. +* `serialNumber` string (optional) - The USB device serial number. +* `usbVersionMajor` Integer - The USB protocol major version supported by the device. +* `usbVersionMinor` Integer - The USB protocol minor version supported by the device. +* `usbVersionSubminor` Integer - The USB protocol subminor version supported by the device. +* `vendorId` Integer - The USB vendor ID. diff --git a/docs/latest/api/structures/web-preferences.md b/docs/latest/api/structures/web-preferences.md index d3a3d5009..277e54996 100644 --- a/docs/latest/api/structures/web-preferences.md +++ b/docs/latest/api/structures/web-preferences.md @@ -96,6 +96,11 @@ hide_title: false paint event. Defaults to `false`. See the [offscreen rendering tutorial](../../tutorial/offscreen-rendering.md) for more details. + * `sharedTexturePixelFormat` string (optional) _Experimental_ - The requested output format of the shared texture. Defaults to `argb`. + The name is originated from Chromium [`media::VideoPixelFormat`](https://source.chromium.org/chromium/chromium/src/+/main:media/base/video_types.h) enum suffix and only subset of them are supported. + The actual output pixel format and color space of the texture should refer to [`OffscreenSharedTexture`](../structures/offscreen-shared-texture.md) object in the `paint` event. + * `argb` - The requested output texture format is 8-bit unorm RGBA, with SRGB SDR color space. + * `rgbaf16` - The requested output texture format is 16-bit float RGBA, with scRGB HDR color space. * `contextIsolation` boolean (optional) - Whether to run Electron APIs and the specified `preload` script in a separate JavaScript context. Defaults to `true`. The context that the `preload` script runs in will only have diff --git a/docs/latest/api/system-preferences.md b/docs/latest/api/system-preferences.md index 07ac21b2c..03382c94e 100644 --- a/docs/latest/api/system-preferences.md +++ b/docs/latest/api/system-preferences.md @@ -21,7 +21,7 @@ console.log(systemPreferences.getEffectiveAppearance()) The `systemPreferences` object emits the following events: -### Event: 'accent-color-changed' _Windows_ +### Event: 'accent-color-changed' _Windows_ _Linux_ Returns: @@ -189,7 +189,7 @@ Some popular `key` and `type`s are: Removes the `key` in `NSUserDefaults`. This can be used to restore the default or global value of a `key` previously set with `setUserDefault`. -### `systemPreferences.getAccentColor()` _Windows_ _macOS_ +### `systemPreferences.getAccentColor()` Returns `string` - The users current system wide accent color preference in RGBA hexadecimal form. diff --git a/docs/latest/breaking-changes.md b/docs/latest/breaking-changes.md index 162bf38e0..cf008108f 100644 --- a/docs/latest/breaking-changes.md +++ b/docs/latest/breaking-changes.md @@ -19,6 +19,37 @@ This document uses the following convention to categorize breaking changes: * **Deprecated:** An API was marked as deprecated. The API will continue to function, but will emit a deprecation warning, and will be removed in a future release. * **Removed:** An API or feature was removed, and is no longer supported by Electron. +## Planned Breaking API Changes (39.0) + +### Deprecated: `--host-rules` command line switch + +Chromium is deprecating the `--host-rules` switch. + +You should use `--host-resolver-rules` instead. + +### Behavior Changed: window.open popups are always resizable + +Per current [WHATWG spec](https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-open-dev), the `window.open` API will now always create a resizable popup window. + +To restore previous behavior: + +```js +webContents.setWindowOpenHandler((details) => { + return { + action: 'allow', + overrideBrowserWindowOptions: { + resizable: details.features.includes('resizable=yes') + } + } +}) +``` + +### Behavior Changed: shared texture OSR `paint` event data structure + +When using shared texture offscreen rendering feature, the `paint` event now emits a more structured object. +It moves the `sharedTextureHandle`, `planes`, `modifier` into a unified `handle` property. +See [here](https://www.electronjs.org/docs/latest/api/structures/offscreen-shared-texture) for more details. + ## Planned Breaking API Changes (38.0) ### Removed: `ELECTRON_OZONE_PLATFORM_HINT` environment variable diff --git a/docs/latest/glossary.md b/docs/latest/glossary.md index 421c5952c..4e86077f5 100644 --- a/docs/latest/glossary.md +++ b/docs/latest/glossary.md @@ -19,6 +19,15 @@ The ASAR format was created primarily to improve performance on Windows when reading large quantities of small files (e.g. when loading your app's JavaScript dependency tree from `node_modules`). +### ASAR integrity + +ASAR integrity is an security feature that validates the contents of your app's +ASAR archives at runtime. When enabled, your Electron app will verify the +header hash of its ASAR archive on runtime. If no hash is present or if there is a mismatch in the +hashes, the app will forcefully terminate. + +See the [ASAR Integrity](./tutorial/asar-integrity.md) guide for more details. + ### code signing Code signing is a process where an app developer digitally signs their code to diff --git a/docs/latest/tutorial/asar-integrity.md b/docs/latest/tutorial/asar-integrity.md index 38903628d..f1067eea9 100644 --- a/docs/latest/tutorial/asar-integrity.md +++ b/docs/latest/tutorial/asar-integrity.md @@ -5,7 +5,7 @@ slug: asar-integrity hide_title: false --- -ASAR integrity is an experimental feature that validates the contents of your app's +ASAR integrity is a security feature that validates the contents of your app's [ASAR archives](./asar-archives.md) at runtime. ## Version support @@ -77,7 +77,7 @@ on package time. The process of providing this packaged hash is different for ma ### Using Electron tooling Electron Forge and Electron Packager do this setup automatically for you with no additional -configuration. The minimum required versions for ASAR integrity are: +configuration whenever `asar` is enabled. The minimum required versions for ASAR integrity are: * `@electron/packager@18.3.1` * `@electron/forge@7.4.0` diff --git a/docs/latest/tutorial/automated-testing.md b/docs/latest/tutorial/automated-testing.md index 984bfee23..ab821a4c4 100644 --- a/docs/latest/tutorial/automated-testing.md +++ b/docs/latest/tutorial/automated-testing.md @@ -81,46 +81,22 @@ describe('keyboard input', () => { Furthermore, WebdriverIO allows you to access Electron APIs to get static information about your application: ```js @ts-nocheck -import { browser, $, expect } from '@wdio/globals' - -describe('when the make smaller button is clicked', () => { - it('should decrease the window height and width by 10 pixels', async () => { - const boundsBefore = await browser.electron.browserWindow('getBounds') - expect(boundsBefore.width).toEqual(210) - expect(boundsBefore.height).toEqual(310) - - await $('.make-smaller').click() - const boundsAfter = await browser.electron.browserWindow('getBounds') - expect(boundsAfter.width).toEqual(200) - expect(boundsAfter.height).toEqual(300) - }) -}) -``` - -or to retrieve other Electron process information: - -```js @ts-nocheck -import fs from 'node:fs' -import path from 'node:path' - -import { browser, expect } from '@wdio/globals' - -const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'package.json'), { encoding: 'utf-8' })) -const { name, version } = packageJson - -describe('electron APIs', () => { - it('should retrieve app metadata through the electron API', async () => { - const appName = await browser.electron.app('getName') - expect(appName).toEqual(name) - const appVersion = await browser.electron.app('getVersion') - expect(appVersion).toEqual(version) - }) - - it('should pass args through to the launched application', async () => { - // custom args are set in the wdio.conf.js file as they need to be set before WDIO starts - const argv = await browser.electron.mainProcess('argv') - expect(argv).toContain('--foo') - expect(argv).toContain('--bar=baz') +import { browser } from '@wdio/globals' + +describe('trigger message modal', async () => { + it('message modal can be triggered from a test', async () => { + await browser.electron.execute( + (electron, param1, param2, param3) => { + const appWindow = electron.BrowserWindow.getFocusedWindow() + electron.dialog.showMessageBox(appWindow, { + message: 'Hello World!', + detail: `${param1} + ${param2} + ${param3} = ${param1 + param2 + param3}` + }) + }, + 1, + 2, + 3 + ) }) }) ``` @@ -214,7 +190,7 @@ npm install --save-dev @playwright/test :::caution Dependencies -This tutorial was written with `@playwright/test@1.41.1`. Check out +This tutorial was written with `@playwright/test@1.52.0`. Check out [Playwright's releases][playwright-releases] page to learn about changes that might affect the code below. @@ -227,10 +203,10 @@ To point this API to your Electron app, you can pass the path to your main proce entry point (here, it is `main.js`). ```js {5} @ts-nocheck -const { test, _electron: electron } = require('@playwright/test') +import { test, _electron as electron } from '@playwright/test' test('launch app', async () => { - const electronApp = await electron.launch({ args: ['main.js'] }) + const electronApp = await electron.launch({ args: ['.'] }) // close app await electronApp.close() }) @@ -240,10 +216,10 @@ After that, you will access to an instance of Playwright's `ElectronApp` class. is a powerful class that has access to main process modules for example: ```js {5-10} @ts-nocheck -const { test, _electron: electron } = require('@playwright/test') +import { test, _electron as electron } from '@playwright/test' test('get isPackaged', async () => { - const electronApp = await electron.launch({ args: ['main.js'] }) + const electronApp = await electron.launch({ args: ['.'] }) const isPackaged = await electronApp.evaluate(async ({ app }) => { // This runs in Electron's main process, parameter here is always // the result of the require('electron') in the main app script. @@ -259,10 +235,10 @@ It can also create individual [Page][playwright-page] objects from Electron Brow For example, to grab the first BrowserWindow and save a screenshot: ```js {6-7} @ts-nocheck -const { test, _electron: electron } = require('@playwright/test') +import { test, _electron as electron } from '@playwright/test' test('save screenshot', async () => { - const electronApp = await electron.launch({ args: ['main.js'] }) + const electronApp = await electron.launch({ args: ['.'] }) const window = await electronApp.firstWindow() await window.screenshot({ path: 'intro.png' }) // close app @@ -274,7 +250,7 @@ Putting all this together using the Playwright test-runner, let's create a `exam test file with a single test and assertion: ```js title='example.spec.js' @ts-nocheck -const { test, expect, _electron: electron } = require('@playwright/test') +import { test, expect, _electron as electron } from '@playwright/test' test('example test', async () => { const electronApp = await electron.launch({ args: ['.'] }) diff --git a/docs/latest/tutorial/electron-timelines.md b/docs/latest/tutorial/electron-timelines.md index db1154b99..3b4c7a79f 100644 --- a/docs/latest/tutorial/electron-timelines.md +++ b/docs/latest/tutorial/electron-timelines.md @@ -20,7 +20,7 @@ check out our [Electron Versioning](./electron-versioning.md) doc. | 38.0.0 | 2025-Jun-26 | 2025-Aug-06 | 2025-Sep-02 | 2026-Mar-10 | M140 | v22.18 | ✅ | | 37.0.0 | 2025-May-01 | 2025-May-28 | 2025-Jun-24 | 2026-Jan-13 | M138 | v22.16 | ✅ | | 36.0.0 | 2025-Mar-06 | 2025-Apr-02 | 2025-Apr-29 | 2025-Oct-28 | M136 | v22.14 | ✅ | -| 35.0.0 | 2025-Jan-16 | 2025-Feb-05 | 2025-Mar-04 | 2025-Sep-02 | M134 | v22.14 | 🚫 | +| 35.0.0 | 2025-Jan-16 | 2025-Feb-05 | 2025-Mar-04 | 2025-Sep-02 | M134 | v22.14 | ✅ | | 34.0.0 | 2024-Oct-17 | 2024-Nov-13 | 2025-Jan-14 | 2025-Jun-24 | M132 | v20.18 | 🚫 | | 33.0.0 | 2024-Aug-22 | 2024-Sep-18 | 2024-Oct-15 | 2025-Apr-29 | M130 | v20.18 | 🚫 | | 32.0.0 | 2024-Jun-14 | 2024-Jul-24 | 2024-Aug-20 | 2025-Mar-04 | M128 | v20.16 | 🚫 | diff --git a/docs/latest/tutorial/fuses.md b/docs/latest/tutorial/fuses.md index f71b0f024..29dbc98fe 100644 --- a/docs/latest/tutorial/fuses.md +++ b/docs/latest/tutorial/fuses.md @@ -11,11 +11,24 @@ hide_title: false ## What are fuses? -For a subset of Electron functionality it makes sense to disable certain features for an entire application. For example, 99% of apps don't make use of `ELECTRON_RUN_AS_NODE`, these applications want to be able to ship a binary that is incapable of using that feature. We also don't want Electron consumers building Electron from source as that is both a massive technical challenge and has a high cost of both time and money. +From a security perspective, it makes sense to disable certain unused Electron features +that are powerful but may make your app's security posture weaker. For example, any app that doesn't +use the `ELECTRON_RUN_AS_NODE` environment variable would want to disable the feature to prevent a +subset of "living off the land" attacks. -Fuses are the solution to this problem, at a high level they are "magic bits" in the Electron binary that can be flipped when packaging your Electron app to enable / disable certain features / restrictions. Because they are flipped at package time before you code sign your app the OS becomes responsible for ensuring those bits aren't flipped back via OS level code signing validation (Gatekeeper / App Locker). +We also don't want Electron consumers forking to achieve this goal, as building from source and +maintaining a fork is a massive technical challenge and costs a lot of time and money. -## Current Fuses +Fuses are the solution to this problem. At a high level, they are "magic bits" in the Electron binary +that can be flipped when packaging your Electron app to enable or disable certain features/restrictions. + +Because they are flipped at package time before you code sign your app, the OS becomes responsible +for ensuring those bits aren't flipped back via OS-level code signing validation +(e.g. [Gatekeeper](https://support.apple.com/en-ca/guide/security/sec5599b66df/web) on macOS or +[AppLocker](https://learn.microsoft.com/en-us/windows/security/application-security/application-control/app-control-for-business/applocker/applocker-overview) +on Windows). + +## Current fuses ### `runAsNode` @@ -23,7 +36,11 @@ Fuses are the solution to this problem, at a high level they are "magic bits" in **@electron/fuses:** `FuseV1Options.RunAsNode` -The runAsNode fuse toggles whether the `ELECTRON_RUN_AS_NODE` environment variable is respected or not. Please note that if this fuse is disabled then `process.fork` in the main process will not function as expected as it depends on this environment variable to function. Instead, we recommend that you use [Utility Processes](../api/utility-process.md), which work for many use cases where you need a standalone Node.js process (like a Sqlite server process or similar scenarios). +The `runAsNode` fuse toggles whether the [`ELECTRON_RUN_AS_NODE`](../api/environment-variables.md) +environment variable is respected or not. With this fuse disabled, [`child_process.fork`](https://nodejs.org/api/child_process.html#child_processforkmodulepath-args-options) in the main process will not function +as expected, as it depends on this environment variable to function. Instead, we recommend that you +use [Utility Processes](../api/utility-process.md), which work for many use cases where you need a +standalone Node.js process (e.g. a SQLite server process). ### `cookieEncryption` @@ -31,7 +48,12 @@ The runAsNode fuse toggles whether the `ELECTRON_RUN_AS_NODE` environment variab **@electron/fuses:** `FuseV1Options.EnableCookieEncryption` -The cookieEncryption fuse toggles whether the cookie store on disk is encrypted using OS level cryptography keys. By default the sqlite database that Chromium uses to store cookies stores the values in plaintext. If you wish to ensure your apps cookies are encrypted in the same way Chrome does then you should enable this fuse. Please note it is a one-way transition, if you enable this fuse existing unencrypted cookies will be encrypted-on-write but if you then disable the fuse again your cookie store will effectively be corrupt and useless. Most apps can safely enable this fuse. +The `cookieEncryption` fuse toggles whether the cookie store on disk is encrypted using OS level +cryptography keys. By default, the SQLite database that Chromium uses to store cookies stores the +values in plaintext. If you wish to ensure your app's cookies are encrypted in the same way Chrome +does, then you should enable this fuse. Please note it is a one-way transition—if you enable this +fuse, existing unencrypted cookies will be encrypted-on-write, but subsequently disabling the fuse +later will make your cookie store corrupt and useless. Most apps can safely enable this fuse. ### `nodeOptions` @@ -39,7 +61,11 @@ The cookieEncryption fuse toggles whether the cookie store on disk is encrypted **@electron/fuses:** `FuseV1Options.EnableNodeOptionsEnvironmentVariable` -The nodeOptions fuse toggles whether the [`NODE_OPTIONS`](https://nodejs.org/api/cli.html#node_optionsoptions) and [`NODE_EXTRA_CA_CERTS`](https://github.com/nodejs/node/blob/main/doc/api/cli.md#node_extra_ca_certsfile) environment variables are respected. The `NODE_OPTIONS` environment variable can be used to pass all kinds of custom options to the Node.js runtime and isn't typically used by apps in production. Most apps can safely disable this fuse. +The `nodeOptions` fuse toggles whether the [`NODE_OPTIONS`](https://nodejs.org/api/cli.html#node_optionsoptions) +and [`NODE_EXTRA_CA_CERTS`](https://github.com/nodejs/node/blob/main/doc/api/cli.md#node_extra_ca_certsfile) +environment variables are respected. The `NODE_OPTIONS` environment variable can be used to pass all +kinds of custom options to the Node.js runtime and isn't typically used by apps in production. +Most apps can safely disable this fuse. ### `nodeCliInspect` @@ -47,7 +73,9 @@ The nodeOptions fuse toggles whether the [`NODE_OPTIONS`](https://nodejs.org/api **@electron/fuses:** `FuseV1Options.EnableNodeCliInspectArguments` -The nodeCliInspect fuse toggles whether the `--inspect`, `--inspect-brk`, etc. flags are respected or not. When disabled it also ensures that `SIGUSR1` signal does not initialize the main process inspector. Most apps can safely disable this fuse. +The `nodeCliInspect` fuse toggles whether the `--inspect`, `--inspect-brk`, etc. flags are respected +or not. When disabled, it also ensures that `SIGUSR1` signal does not initialize the main process +inspector. Most apps can safely disable this fuse. ### `embeddedAsarIntegrityValidation` @@ -55,9 +83,12 @@ The nodeCliInspect fuse toggles whether the `--inspect`, `--inspect-brk`, etc. f **@electron/fuses:** `FuseV1Options.EnableEmbeddedAsarIntegrityValidation` -The embeddedAsarIntegrityValidation fuse toggles an experimental feature on macOS and Windows that validates the content of the `app.asar` file when it is loaded. This feature is designed to have a minimal performance impact but may marginally slow down file reads from inside the `app.asar` archive. +The `embeddedAsarIntegrityValidation` fuse toggles a feature on macOS and Windows that validates the +content of the `app.asar` file when it is loaded. This feature is designed to have a minimal +performance impact but may marginally slow down file reads from inside the `app.asar` archive. +Most apps can safely enable this fuse. -For more information on how to use asar integrity validation please read the [Asar Integrity](asar-integrity.md) documentation. +For more information on how to use ASAR integrity validation, please read the [Asar Integrity](asar-integrity.md) documentation. ### `onlyLoadAppFromAsar` @@ -65,7 +96,15 @@ For more information on how to use asar integrity validation please read the [As **@electron/fuses:** `FuseV1Options.OnlyLoadAppFromAsar` -The onlyLoadAppFromAsar fuse changes the search system that Electron uses to locate your app code. By default Electron will search in the following order `app.asar` -> `app` -> `default_app.asar`. When this fuse is enabled the search order becomes a single entry `app.asar` thus ensuring that when combined with the `embeddedAsarIntegrityValidation` fuse it is impossible to load non-validated code. +The `onlyLoadAppFromAsar` fuse changes the search system that Electron uses to locate your app code. +By default, Electron will search for this code in the following order: + +1. `app.asar` +1. `app` +1. `default_app.asar` + +When this fuse is enabled, Electron will _only_ search for `app.asar`. When combined with the [`embeddedAsarIntegrityValidation`](#embeddedasarintegrityvalidation) fuse, this fuse ensures that +it is impossible to load non-validated code. ### `loadBrowserProcessSpecificV8Snapshot` @@ -73,11 +112,17 @@ The onlyLoadAppFromAsar fuse changes the search system that Electron uses to loc **@electron/fuses:** `FuseV1Options.LoadBrowserProcessSpecificV8Snapshot` -The loadBrowserProcessSpecificV8Snapshot fuse changes which V8 snapshot file is used for the browser process. By default Electron's processes will all use the same V8 snapshot file. When this fuse is enabled the browser process uses the file called `browser_v8_context_snapshot.bin` for its V8 snapshot. The other processes will use the V8 snapshot file that they normally do. +V8 snapshots can be useful to improve app startup performance. V8 lets you take snapshots of +initialized heaps and then load them back in to avoid the cost of initializing the heap. -V8 snapshots can be useful to improve app startup performance. V8 lets you take snapshots of initialized heaps and then load them back in to avoid the cost of initializing the heap. +The `loadBrowserProcessSpecificV8Snapshot` fuse changes which V8 snapshot file is used for the browser +process. By default, Electron's processes will all use the same V8 snapshot file. When this fuse is +enabled, the main process uses the file called `browser_v8_context_snapshot.bin` for its V8 snapshot. +Other processes will use the V8 snapshot file that they normally do. -Using separate snapshots for renderer processes and the main process can improve security, especially to make sure that the renderer doesn't use a snapshot with `nodeIntegration` enabled. See [#35170](https://github.com/electron/electron/issues/35170) for details. +Using separate snapshots for renderer processes and the main process can improve security, especially +to make sure that the renderer doesn't use a snapshot with `nodeIntegration` enabled. +See [electron/electron#35170](https://github.com/electron/electron/issues/35170) for details. ### `grantFileProtocolExtraPrivileges` @@ -85,19 +130,25 @@ Using separate snapshots for renderer processes and the main process can improve **@electron/fuses:** `FuseV1Options.GrantFileProtocolExtraPrivileges` -The grantFileProtocolExtraPrivileges fuse changes whether pages loaded from the `file://` protocol are given privileges beyond what they would receive in a traditional web browser. This behavior was core to Electron apps in original versions of Electron but is no longer required as apps should be [serving local files from custom protocols](./security.md#18-avoid-usage-of-the-file-protocol-and-prefer-usage-of-custom-protocols) now instead. If you aren't serving pages from `file://` you should disable this fuse. +The `grantFileProtocolExtraPrivileges` fuse changes whether pages loaded from the `file://` protocol +are given privileges beyond what they would receive in a traditional web browser. This behavior was +core to Electron apps in original versions of Electron, but is no longer required as apps should be +[serving local files from custom protocols](./security.md#18-avoid-usage-of-the-file-protocol-and-prefer-usage-of-custom-protocols) now instead. + +If you aren't serving pages from `file://`, you should disable this fuse. The extra privileges granted to the `file://` protocol by this fuse are incompletely documented below: * `file://` protocol pages can use `fetch` to load other assets over `file://` * `file://` protocol pages can use service workers -* `file://` protocol pages have universal access granted to child frames also running on `file://` protocols regardless of sandbox settings +* `file://` protocol pages have universal access granted to child frames also running on `file://` + protocols regardless of sandbox settings -## How do I flip the fuses? +## How do I flip fuses? ### The easy way -We've made a handy module, [`@electron/fuses`](https://npmjs.com/package/@electron/fuses), to make flipping these fuses easy. Check out the README of that module for more details on usage and potential error cases. +[`@electron/fuses`](https://npmjs.com/package/@electron/fuses) is a JavaScript utility designed to make flipping these fuses easy. Check out the README of that module for more details on usage and potential error cases. ```js @ts-nocheck const { flipFuses, FuseVersion, FuseV1Options } = require('@electron/fuses') @@ -113,29 +164,37 @@ flipFuses( ) ``` -You can validate the fuses have been flipped or check the fuse status of an arbitrary Electron app using the fuses CLI. +You can validate the fuses that have been flipped or check the fuse status of an arbitrary Electron +app using the `@electron/fuses` CLI. ```bash npx @electron/fuses read --app /Applications/Foo.app ``` -### The hard way +>[!NOTE] +> If you are using Electron Forge to distribute your application, you can flip fuses using +> [`@electron-forge/plugin-fuses`](https://www.electronforge.io/config/plugins/fuses), +> which comes pre-installed with all templates. -#### Quick Glossary +### The hard way -* **Fuse Wire**: A sequence of bytes in the Electron binary used to control the fuses -* **Sentinel**: A static known sequence of bytes you can use to locate the fuse wire -* **Fuse Schema**: The format / allowed values for the fuse wire +> [!IMPORTANT] +> Glossary: +> +> * **Fuse Wire**: A sequence of bytes in the Electron binary used to control the fuses +> * **Sentinel**: A static known sequence of bytes you can use to locate the fuse wire +> * **Fuse Schema**: The format/allowed values for the fuse wire -Manually flipping fuses requires editing the Electron binary and modifying the fuse wire to be the sequence of bytes that represent the state of the fuses you want. +Manually flipping fuses requires editing the Electron binary and modifying the fuse wire to be the +sequence of bytes that represent the state of the fuses you want. -Somewhere in the Electron binary there will be a sequence of bytes that look like this: +Somewhere in the Electron binary, there will be a sequence of bytes that look like this: ```text | ...binary | sentinel_bytes | fuse_version | fuse_wire_length | fuse_wire | ...binary | ``` -* `sentinel_bytes` is always this exact string `dL7pKGdnNz796PbbjQWNKmHXBZaB9tsX` +* `sentinel_bytes` is always this exact string: `dL7pKGdnNz796PbbjQWNKmHXBZaB9tsX` * `fuse_version` is a single byte whose unsigned integer value represents the version of the fuse schema * `fuse_wire_length` is a single byte whose unsigned integer value represents the number of fuses in the following fuse wire * `fuse_wire` is a sequence of N bytes, each byte represents a single fuse and its state. @@ -143,6 +202,6 @@ Somewhere in the Electron binary there will be a sequence of bytes that look lik * "1" (0x31) indicates the fuse is enabled * "r" (0x72) indicates the fuse has been removed and changing the byte to either 1 or 0 will have no effect. -To flip a fuse you find its position in the fuse wire and change it to "0" or "1" depending on the state you'd like. +To flip a fuse, you find its position in the fuse wire and change it to "0" or "1" depending on the state you'd like. You can view the current schema [here](https://github.com/electron/electron/blob/main/build/fuses/fuses.json5). diff --git a/docs/latest/tutorial/online-offline-events.md b/docs/latest/tutorial/online-offline-events.md index 719e5d17f..a4812c216 100644 --- a/docs/latest/tutorial/online-offline-events.md +++ b/docs/latest/tutorial/online-offline-events.md @@ -1,6 +1,6 @@ --- title: "Online/Offline Event Detection" -description: "Online and offline event detection can be implemented in the Renderer process using the navigator.onLine attribute, part of standard HTML5 API." +description: "Online and offline event detection can be implemented in both the main and renderer processes:" slug: online-offline-events hide_title: false --- @@ -9,15 +9,15 @@ hide_title: false ## Overview -[Online and offline event](https://developer.mozilla.org/en-US/docs/Online_and_offline_events) -detection can be implemented in the Renderer process using the -[`navigator.onLine`](http://html5index.org/Offline%20-%20NavigatorOnLine.html) -attribute, part of standard HTML5 API. +Online and offline event detection can be implemented in both the main and renderer processes: + +- **Renderer process**: Use the [`navigator.onLine`](http://html5index.org/Offline%20-%20NavigatorOnLine.html) attribute and [online/offline events](https://developer.mozilla.org/en-US/docs/Online_and_offline_events), part of standard HTML5 API. +- **Main process**: Use the [`net.isOnline()`](../api/net.md#netisonline) method or the [`net.online`](../api/net.md#netonline-readonly) property. The `navigator.onLine` attribute returns: -* `false` if all network requests are guaranteed to fail (e.g. when disconnected from the network). -* `true` in all other cases. +- `false` if all network requests are guaranteed to fail (e.g. when disconnected from the network). +- `true` in all other cases. Since many cases return `true`, you should treat with care situations of getting false positives, as we cannot always assume that `true` value means @@ -26,7 +26,27 @@ is running a virtualization software that has virtual Ethernet adapters in "alwa connected" state. Therefore, if you want to determine the Internet access status of Electron, you should develop additional means for this check. -## Example +## Main Process Detection + +In the main process, you can use the `net` module to detect online/offline status: + +```js +const { net } = require('electron') + +// Method 1: Using net.isOnline() +const isOnline = net.isOnline() +console.log('Online status:', isOnline) + +// Method 2: Using net.online property +console.log('Online status:', net.online) +``` + +Both `net.isOnline()` and `net.online` return the same boolean value with the same reliability characteristics as `navigator.onLine` - they provide a strong indicator when offline (`false`), but a `true` value doesn't guarantee successful internet connectivity. + +> [!NOTE] +> The `net` module is only available after the app emits the `ready` event. + +## Renderer Process Example Starting with an HTML file `index.html`, this example will demonstrate how the `navigator.onLine` API can be used to build a connection status indicator. @@ -91,4 +111,4 @@ After launching the Electron application, you should see the notification: ![Connection status](../images/connection-status.png) > [!NOTE] -> If you need to communicate the connection status to the main process, use the [IPC renderer](../api/ipc-renderer.md) API. +> If you need to check the connection status in the main process, you can use [`net.isOnline()`](../api/net.md#netisonline) directly instead of communicating from the renderer process via [IPC](../api/ipc-renderer.md). diff --git a/docs/latest/tutorial/security.md b/docs/latest/tutorial/security.md index ef1353d73..1bfa4b39f 100644 --- a/docs/latest/tutorial/security.md +++ b/docs/latest/tutorial/security.md @@ -104,7 +104,7 @@ either `process.env` or the `window` object. You should at least follow these steps to improve the security of your application: 1. [Only load secure content](#1-only-load-secure-content) -2. [Disable the Node.js integration in all renderers that display remote content](#2-do-not-enable-nodejs-integration-for-remote-content) +2. [Do not enable Node.js integration for remote content](#2-do-not-enable-nodejs-integration-for-remote-content) 3. [Enable context isolation in all renderers](#3-enable-context-isolation) 4. [Enable process sandboxing](#4-enable-process-sandboxing) 5. [Use `ses.setPermissionRequestHandler()` in all sessions that load remote content](#5-handle-session-permission-requests-from-remote-content) @@ -844,10 +844,10 @@ that your application might have the rights for. #### How? -We've made a module, [`@electron/fuses`](https://npmjs.com/package/@electron/fuses), to make +[`@electron/fuses`](https://npmjs.com/package/@electron/fuses) is a module we made to make flipping these fuses easy. Check out the README of that module for more details on usage and potential error cases, and refer to -[How do I flip the fuses?](./fuses.md#how-do-i-flip-the-fuses) in our documentation. +[How do I flip fuses?](./fuses.md#how-do-i-flip-fuses) in our documentation. ### 20. Do not expose Electron APIs to untrusted web content From 0d20a3e89b1186eff642c4263144338fdeab9864 Mon Sep 17 00:00:00 2001 From: Erick Zhao Date: Tue, 28 Oct 2025 14:41:57 -0700 Subject: [PATCH 2/2] fix breaking changes doc link --- docs/latest/breaking-changes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/latest/breaking-changes.md b/docs/latest/breaking-changes.md index cf008108f..57516ea27 100644 --- a/docs/latest/breaking-changes.md +++ b/docs/latest/breaking-changes.md @@ -48,7 +48,7 @@ webContents.setWindowOpenHandler((details) => { When using shared texture offscreen rendering feature, the `paint` event now emits a more structured object. It moves the `sharedTextureHandle`, `planes`, `modifier` into a unified `handle` property. -See [here](https://www.electronjs.org/docs/latest/api/structures/offscreen-shared-texture) for more details. +See the [OffscreenSharedTexture](./api/structures/offscreen-shared-texture.md) API for more details. ## Planned Breaking API Changes (38.0)