new·Earn with mozg — 20% of every monthSend somebody here and take a fifth of every plan payment they make, for as long as they keep paying — not a bounty on the first invoice. Your handle is the link, the window is thirty days, and the commission lands on your balance the second they pay. Free to join: if you have signed in, you already have the link. mozg.sh/earnall news →
mozg.beta
Sign in

Electron · API · all subjects

webcontents: rendering & performance

32 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

win.getBackgroundColor() method

Returns string - gets the background color of the window in Hex (#RRGGBB) format. The alpha value is not returned alongside the red, green, and blue values.

setBackgroundColor color formats

win.setBackgroundColor() accepts colors in Hex, RGB, RGBA, HSL, HSLA, or named CSS color format. Valid Hex formats: #fff (shorthand RGB), #ffff (shorthand ARGB), #ffffff (RGB), #ffffffff (ARGB). Valid RGB: rgb(255, 255, 255). Valid RGBA: rgba(255, 255, 255, 1.0). Valid HSL: hsl(200, 20%, 50%). Valid HSLA: hsla(200, 20%, 50%, 0.5). Named colors are case-sensitive and similar to CSS Color Module Level 3 keywords, e.g., blueviolet or red.

backgroundColor property and use cases

The backgroundColor property should be set to a color close to the app's background to make the app feel more native. It is recommended to set backgroundColor even for apps that use ready-to-show event. For complex apps where ready-to-show may emit too late, show the window immediately with backgroundColor set.

WebPreferences images property

The `images` boolean property enables or disables image support. Default is `true`.

WebPreferences imageAnimationPolicy property

The `imageAnimationPolicy` string property specifies how to run image animations such as GIFs. Accepted values are `animate`, `animateOnce`, or `noAnimation`. Default is `animate`.

WebPreferences webgl property

The `webgl` boolean property enables or disables WebGL support. Default is `true`.

WebPreferences plugins property

The `plugins` boolean property determines whether plugins should be enabled. Default is `false`.

WebPreferences experimentalFeatures property

The `experimentalFeatures` boolean property enables Chromium's experimental features. Default is `false`.

WebPreferences disableBlinkFeatures property

The `disableBlinkFeatures` string property accepts a comma-separated list of feature strings like `CSSVariables,KeyboardEventKey` to disable. The full list of supported feature strings can be found in the RuntimeEnabledFeatures.json5 file.

WebPreferences defaultFontFamily property

The `defaultFontFamily` object property sets the default font for the font-family with sub-properties: `standard` (defaults to `Times New Roman`), `serif` (defaults to `Times New Roman`), `sansSerif` (defaults to `Arial`), `monospace` (defaults to `Courier New`), `cursive` (defaults to `Script`), `fantasy` (defaults to `Impact`), and `math` (defaults to `Latin Modern Math`).

WebPreferences defaultFontSize property

The `defaultFontSize` integer property sets the default font size. Default is `16`.

WebPreferences defaultMonospaceFontSize property

The `defaultMonospaceFontSize` integer property sets the default monospace font size. Default is `13`.

WebPreferences minimumFontSize property

The `minimumFontSize` integer property sets the minimum font size. Default is `0`.

WebPreferences defaultEncoding property

The `defaultEncoding` string property sets the default character encoding. Default is `ISO-8859-1`.

WebPreferences backgroundThrottling property

The `backgroundThrottling` boolean property determines whether to throttle animations and timers when the page becomes background. This also affects the Page Visibility API. When at least one WebContents displayed in a single BrowserWindow has disabled `backgroundThrottling`, frames will be drawn and swapped for the whole window and other WebContents displayed by it. Default is `true`.

WebPreferences disableHtmlFullscreenWindowResize property

The `disableHtmlFullscreenWindowResize` boolean property determines whether to prevent the window from resizing when entering HTML Fullscreen. Default is `false`.

WebPreferences zoomFactor property

The `zoomFactor` number property sets the default zoom factor of the page. A value of `3.0` represents `300%`. Default is `1.0`.

WebPreferences enableWebSQL property

The `enableWebSQL` boolean property determines whether to enable the WebSQL API. Default is `true`.

WebPreferences v8CacheOptions property

The `v8CacheOptions` string property enforces the v8 code caching policy used by blink. Accepted values are `none` (disables code caching), `code` (heuristic based code caching), `bypassHeatCheck` (bypass code caching heuristics but with lazy compilation), and `bypassHeatCheckAndEagerCompile` (same as above except compilation is eager). Default policy is `code`.

WebPreferences transparent property

The `transparent` boolean property determines whether to enable background transparency for the guest page. Default is `true`. The guest page's text and background colors are derived from the color scheme of its root element. When transparency is enabled, the text color will still change accordingly but the background will remain transparent.

WebPreferences spellcheck property

The `spellcheck` boolean property determines whether to enable the builtin spellchecker. Default is `true`.

WebPreferences zoomMode property

The `zoomMode` string property sets the initial zoom mode for the page. Default is `'default'`. Available modes can be found in the `contents.setZoomMode` documentation.

WebPreferences javascript property

The `javascript` boolean property enables or disables JavaScript support. Default is `true`.

webview zoom methods

setZoomFactor(factor) changes zoom factor (zoom percent divided by 100, so 300% = 3.0). setZoomLevel(level) changes zoom level (0 is original size, each increment is 20% larger/smaller, formula: scale := 1.2 ^ level). getZoomFactor() returns current zoom factor. getZoomLevel() returns current zoom level. setVisualZoomLevelLimits(minimumLevel, maximumLevel) returns Promise<void> and sets maximum and minimum pinch-to-zoom level. Zoom policy at Chromium level is same-origin, meaning zoom level propagates across windows with same domain.

webview enter-html-full-screen and leave-html-full-screen events

enter-html-full-screen event fires when page enters fullscreen triggered by HTML API. leave-html-full-screen event fires when page leaves fullscreen triggered by HTML API.

webview console-message event

console-message event fires when guest window logs console message. Returns: level (Integer from 0 to 3 matching verbose, info, warning, error), message (string, actual console message), line (Integer line number of source), sourceId (string).

webview did-change-theme-color event

did-change-theme-color event emits when page's theme color changes, usually due to meta tag like <meta name='theme-color' content='#ff0000'>. Returns: themeColor (string).

webview context-menu event parameters

context-menu event returns params object with: x (Integer), y (Integer), linkURL (string), linkText (string), pageURL (string), frameURL (string), srcURL (string), mediaType (string: none/image/audio/video/canvas/file/plugin), hasImageContents (boolean), isEditable (boolean), selectionText (string), titleText (string), altText (string), suggestedFilename (string), selectionRect (Rectangle), selectionStartOffset (number), referrerPolicy (Referrer), misspelledWord (string), dictionarySuggestions (string array), frameCharset (string), formControlType (string: button-button/field-set/input-button/input-checkbox/input-color/input-date/input-datetime-local/input-email/input-file/input-hidden/input-image/input-month/input-number/input-password/input-radio/input-range/input-reset/input-search/input-submit/input-telephone/input-text/input-time/input-url/input-week/output/reset-button/select-list/select-multiple/select-one/submit-button/text-area), spellcheckEnabled (boolean), menuSourceType (string: none/mouse/keyboard/touch/touchMenu/longPress/longTap/touchHandle/stylus/adjustSelection/adjustSelectionReset), mediaFlags (object with inError/isPaused/isMuted/hasAudio/isLooping/isControlsVisible/canToggleControls/canPrint/canSave/canShowPictureInPicture/isShowingPictureInPicture/canRotate/canLoop all boolean), editFlags (object with canUndo/canRedo/canCut/canCopy/canPaste/canDelete/canSelectAll/canEditRichly all boolean).

webview CSS styling with flexbox

The webview tag uses display:flex internally to ensure child iframe fills full height and width of webview container. Do not overwrite the default display:flex property unless specifying display:inline-flex for inline layout.

webview.capturePage method

capturePage([rect]) captures snapshot of page within rect. Parameters: rect (optional Rectangle for area to capture). Returns Promise<NativeImage>. Omitting rect captures entire visible page.

webview.executeJavaScript method

executeJavaScript(code[, userGesture]) evaluates code in the page. Parameters: code (string), userGesture (boolean, optional, default false, creates user gesture context for APIs like requestFullScreen). Returns Promise<any> that resolves with code result or rejects if result is rejected promise.

webview CSS injection methods

insertCSS(css) injects CSS into current web page and returns Promise<string> with a key for the inserted CSS. removeInsertedCSS(key) removes inserted CSS from current web page using the key returned by insertCSS.

Give your agent this brain