Header menu logo fable-electron-docs-api

WebPreferences Type

Constructors

Constructor Description

WebPreferences(?devTools, ?nodeIntegration, ?nodeIntegrationInWorker, ?nodeIntegrationInSubFrames, ?preload, ?sandbox, ?session, ?partition, ?zoomFactor, ?javascript, ?webSecurity, ?allowRunningInsecureContent, ?images, ?imageAnimationPolicy, ?textAreasAreResizable, ?webgl, ?plugins, ?experimentalFeatures, ?scrollBounce, ?enableBlinkFeatures, ?disableBlinkFeatures, ?defaultFontFamily, ?defaultFontSize, ?defaultMonospaceFontSize, ?minimumFontSize, ?defaultEncoding, ?backgroundThrottling, ?offscreen, ?contextIsolation, ?webviewTag, ?additionalArguments, ?safeDialogs, ?safeDialogsMessage, ?disableDialogs, ?navigateOnDragDrop, ?autoplayPolicy, ?disableHtmlFullscreenWindowResize, ?accessibleTitle, ?spellcheck, ?enableWebSQL, ?v8CacheOptions, ?enablePreferredSizeMode, ?transparent, ?enableDeprecatedPaste)

Full Usage: WebPreferences(?devTools, ?nodeIntegration, ?nodeIntegrationInWorker, ?nodeIntegrationInSubFrames, ?preload, ?sandbox, ?session, ?partition, ?zoomFactor, ?javascript, ?webSecurity, ?allowRunningInsecureContent, ?images, ?imageAnimationPolicy, ?textAreasAreResizable, ?webgl, ?plugins, ?experimentalFeatures, ?scrollBounce, ?enableBlinkFeatures, ?disableBlinkFeatures, ?defaultFontFamily, ?defaultFontSize, ?defaultMonospaceFontSize, ?minimumFontSize, ?defaultEncoding, ?backgroundThrottling, ?offscreen, ?contextIsolation, ?webviewTag, ?additionalArguments, ?safeDialogs, ?safeDialogsMessage, ?disableDialogs, ?navigateOnDragDrop, ?autoplayPolicy, ?disableHtmlFullscreenWindowResize, ?accessibleTitle, ?spellcheck, ?enableWebSQL, ?v8CacheOptions, ?enablePreferredSizeMode, ?transparent, ?enableDeprecatedPaste)

Parameters:
    ?devTools : bool - Whether to enable DevTools. If it is set to false, can not use BrowserWindow.webContents.openDevTools() to open DevTools. Default is true.
    ?nodeIntegration : bool - Whether node integration is enabled. Default is false.
    ?nodeIntegrationInWorker : bool - Whether node integration is enabled in web workers. Default is false. More about this can be found in Multithreading.
    ?nodeIntegrationInSubFrames : bool - Experimental option for enabling Node.js support in sub-frames such as iframes and child windows. All your preloads will load for every iframe, you can use process.isMainFrame to determine if you are in the main frame or not.
    ?preload : string - Specifies a script that will be loaded before other scripts run in the page. This script will always have access to node APIs no matter whether node integration is turned on or off. The value should be the absolute file path to the script. When node integration is turned off, the preload script can reintroduce Node global symbols back to the global scope. See example here.
    ?sandbox : bool - If set, this will sandbox the renderer associated with the window, making it compatible with the Chromium OS-level sandbox and disabling the Node.js engine. This is not the same as the nodeIntegration option and the APIs available to the preload script are more limited. Default is true since Electron 20. The sandbox will automatically be disabled when nodeIntegration is set to true. Read more about the option here.
    ?session : Session - Sets the session used by the page. Instead of passing the Session object directly, you can also choose to use the partition option instead, which accepts a partition string. When both session and partition are provided, session will be preferred. Default is the default session.
    ?partition : string - Sets the session used by the page according to the session's partition string. If partition starts with persist:, the page will use a persistent session available to all pages in the app with the same partition. If there is no persist: prefix, the page will use an in-memory session. By assigning the same partition, multiple pages can share the same session. Default is the default session.
    ?zoomFactor : float - The default zoom factor of the page, 3.0 represents 300%. Default is 1.0.
    ?javascript : bool - Enables JavaScript support. Default is true.
    ?webSecurity : bool - When false, it will disable the same-origin policy (usually using testing websites by people), and set allowRunningInsecureContent to true if this options has not been set by user. Default is true.
    ?allowRunningInsecureContent : bool - Allow an https page to run JavaScript, CSS or plugins from http URLs. Default is false.
    ?images : bool - Enables image support. Default is true.
    ?imageAnimationPolicy : ImageAnimationPolicy - Specifies how to run image animations (E.g. GIFs). Can be animate, animateOnce or noAnimation. Default is animate.
    ?textAreasAreResizable : bool - Make TextArea elements resizable. Default is true.
    ?webgl : bool - Enables WebGL support. Default is true.
    ?plugins : bool - Whether plugins should be enabled. Default is false.
    ?experimentalFeatures : bool - Enables Chromium's experimental features. Default is false.
    ?scrollBounce : bool - ⚠ OS Compatibility: WIN ❌ | MAC ✔ | LIN ❌ | MAS ❌ || Enables scroll bounce (rubber banding) effect on macOS. Default is false.
    ?enableBlinkFeatures : string - A list of feature strings separated by ,, like CSSVariables,KeyboardEventKey to enable. The full list of supported feature strings can be found in the RuntimeEnabledFeatures.json5 file.
    ?disableBlinkFeatures : string - A list of feature strings separated by ,, like CSSVariables,KeyboardEventKey to disable. The full list of supported feature strings can be found in the RuntimeEnabledFeatures.json5 file.
    ?defaultFontFamily : DefaultFontFamily - Sets the default font for the font-family.
    ?defaultFontSize : int - Defaults to 16.
    ?defaultMonospaceFontSize : int - Defaults to 13.
    ?minimumFontSize : int - Defaults to 0.
    ?defaultEncoding : string - Defaults to ISO-8859-1.
    ?backgroundThrottling : bool - 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 then frames will be drawn and swapped for the whole window and other webContents displayed by it. Defaults to true.
    ?offscreen : U2<Offscreen, bool> - Whether to enable offscreen rendering for the browser window. Defaults to false. See the offscreen rendering tutorial for more details.
    ?contextIsolation : bool - 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 access to its own dedicated document and window globals, as well as its own set of JavaScript builtins (Array, Object, JSON, etc.), which are all invisible to the loaded content. The Electron API will only be available in the preload script and not the loaded page. This option should be used when loading potentially untrusted remote content to ensure the loaded content cannot tamper with the preload script and any Electron APIs being used. This option uses the same technique used by Chrome Content Scripts. You can access this context in the dev tools by selecting the 'Electron Isolated Context' entry in the combo box at the top of the Console tab.
    ?webviewTag : bool - Whether to enable the <webview> tag. Defaults to false. **Note:** The preload script configured for the <webview> will have node integration enabled when it is executed so you should ensure remote/untrusted content is not able to create a <webview> tag with a possibly malicious preload script. You can use the will-attach-webview event on webContents to strip away the preload script and to validate or alter the <webview>'s initial settings.
    ?additionalArguments : string[] - A list of strings that will be appended to process.argv in the renderer process of this app. Useful for passing small bits of data down to renderer process preload scripts.
    ?safeDialogs : bool - Whether to enable browser style consecutive dialog protection. Default is false.
    ?safeDialogsMessage : string - The message to display when consecutive dialog protection is triggered. If not defined the default message would be used, note that currently the default message is in English and not localized.
    ?disableDialogs : bool - Whether to disable dialogs completely. Overrides safeDialogs. Default is false.
    ?navigateOnDragDrop : bool - Whether dragging and dropping a file or link onto the page causes a navigation. Default is false.
    ?autoplayPolicy : AutoplayPolicy - Autoplay policy to apply to content in the window, can be no-user-gesture-required, user-gesture-required, document-user-activation-required. Defaults to no-user-gesture-required.
    ?disableHtmlFullscreenWindowResize : bool - Whether to prevent the window from resizing when entering HTML Fullscreen. Default is false.
    ?accessibleTitle : string - An alternative title string provided only to accessibility tools such as screen readers. This string is not directly visible to users.
    ?spellcheck : bool - Whether to enable the builtin spellchecker. Default is true.
    ?enableWebSQL : bool - Whether to enable the WebSQL api. Default is true.
    ?v8CacheOptions : V8CacheOptions - Enforces the v8 code caching policy used by blink. Accepted values are
    ?enablePreferredSizeMode : bool - Whether to enable preferred size mode. The preferred size is the minimum size needed to contain the layout of the document—without requiring scrolling. Enabling this will cause the preferred-size-changed event to be emitted on the WebContents when the preferred size changes. Default is false.
    ?transparent : bool - Whether to enable background transparency for the guest page. Default is true. **Note:** 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.
    ?enableDeprecatedPaste : bool - Whether to enable the paste execCommand. Default is false.

Returns: WebPreferences
?devTools : bool

Whether to enable DevTools. If it is set to false, can not use BrowserWindow.webContents.openDevTools() to open DevTools. Default is true.

?nodeIntegration : bool

Whether node integration is enabled. Default is false.

?nodeIntegrationInWorker : bool

Whether node integration is enabled in web workers. Default is false. More about this can be found in Multithreading.

?nodeIntegrationInSubFrames : bool

Experimental option for enabling Node.js support in sub-frames such as iframes and child windows. All your preloads will load for every iframe, you can use process.isMainFrame to determine if you are in the main frame or not.

?preload : string

Specifies a script that will be loaded before other scripts run in the page. This script will always have access to node APIs no matter whether node integration is turned on or off. The value should be the absolute file path to the script. When node integration is turned off, the preload script can reintroduce Node global symbols back to the global scope. See example here.

?sandbox : bool

If set, this will sandbox the renderer associated with the window, making it compatible with the Chromium OS-level sandbox and disabling the Node.js engine. This is not the same as the nodeIntegration option and the APIs available to the preload script are more limited. Default is true since Electron 20. The sandbox will automatically be disabled when nodeIntegration is set to true. Read more about the option here.

?session : Session

Sets the session used by the page. Instead of passing the Session object directly, you can also choose to use the partition option instead, which accepts a partition string. When both session and partition are provided, session will be preferred. Default is the default session.

?partition : string

Sets the session used by the page according to the session's partition string. If partition starts with persist:, the page will use a persistent session available to all pages in the app with the same partition. If there is no persist: prefix, the page will use an in-memory session. By assigning the same partition, multiple pages can share the same session. Default is the default session.

?zoomFactor : float

The default zoom factor of the page, 3.0 represents 300%. Default is 1.0.

?javascript : bool

Enables JavaScript support. Default is true.

?webSecurity : bool

When false, it will disable the same-origin policy (usually using testing websites by people), and set allowRunningInsecureContent to true if this options has not been set by user. Default is true.

?allowRunningInsecureContent : bool

Allow an https page to run JavaScript, CSS or plugins from http URLs. Default is false.

?images : bool

Enables image support. Default is true.

?imageAnimationPolicy : ImageAnimationPolicy

Specifies how to run image animations (E.g. GIFs). Can be animate, animateOnce or noAnimation. Default is animate.

?textAreasAreResizable : bool

Make TextArea elements resizable. Default is true.

?webgl : bool

Enables WebGL support. Default is true.

?plugins : bool

Whether plugins should be enabled. Default is false.

?experimentalFeatures : bool

Enables Chromium's experimental features. Default is false.

?scrollBounce : bool

⚠ OS Compatibility: WIN ❌ | MAC ✔ | LIN ❌ | MAS ❌ || Enables scroll bounce (rubber banding) effect on macOS. Default is false.

?enableBlinkFeatures : string

A list of feature strings separated by ,, like CSSVariables,KeyboardEventKey to enable. The full list of supported feature strings can be found in the RuntimeEnabledFeatures.json5 file.

?disableBlinkFeatures : string

A list of feature strings separated by ,, like CSSVariables,KeyboardEventKey to disable. The full list of supported feature strings can be found in the RuntimeEnabledFeatures.json5 file.

?defaultFontFamily : DefaultFontFamily

Sets the default font for the font-family.

?defaultFontSize : int

Defaults to 16.

?defaultMonospaceFontSize : int

Defaults to 13.

?minimumFontSize : int

Defaults to 0.

?defaultEncoding : string

Defaults to ISO-8859-1.

?backgroundThrottling : bool

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 then frames will be drawn and swapped for the whole window and other webContents displayed by it. Defaults to true.

?offscreen : U2<Offscreen, bool>

Whether to enable offscreen rendering for the browser window. Defaults to false. See the offscreen rendering tutorial for more details.

?contextIsolation : bool

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 access to its own dedicated document and window globals, as well as its own set of JavaScript builtins (Array, Object, JSON, etc.), which are all invisible to the loaded content. The Electron API will only be available in the preload script and not the loaded page. This option should be used when loading potentially untrusted remote content to ensure the loaded content cannot tamper with the preload script and any Electron APIs being used. This option uses the same technique used by Chrome Content Scripts. You can access this context in the dev tools by selecting the 'Electron Isolated Context' entry in the combo box at the top of the Console tab.

?webviewTag : bool

Whether to enable the <webview> tag. Defaults to false. **Note:** The preload script configured for the <webview> will have node integration enabled when it is executed so you should ensure remote/untrusted content is not able to create a <webview> tag with a possibly malicious preload script. You can use the will-attach-webview event on webContents to strip away the preload script and to validate or alter the <webview>'s initial settings.

?additionalArguments : string[]

A list of strings that will be appended to process.argv in the renderer process of this app. Useful for passing small bits of data down to renderer process preload scripts.

?safeDialogs : bool

Whether to enable browser style consecutive dialog protection. Default is false.

?safeDialogsMessage : string

The message to display when consecutive dialog protection is triggered. If not defined the default message would be used, note that currently the default message is in English and not localized.

?disableDialogs : bool

Whether to disable dialogs completely. Overrides safeDialogs. Default is false.

?navigateOnDragDrop : bool

Whether dragging and dropping a file or link onto the page causes a navigation. Default is false.

?autoplayPolicy : AutoplayPolicy

Autoplay policy to apply to content in the window, can be no-user-gesture-required, user-gesture-required, document-user-activation-required. Defaults to no-user-gesture-required.

?disableHtmlFullscreenWindowResize : bool

Whether to prevent the window from resizing when entering HTML Fullscreen. Default is false.

?accessibleTitle : string

An alternative title string provided only to accessibility tools such as screen readers. This string is not directly visible to users.

?spellcheck : bool

Whether to enable the builtin spellchecker. Default is true.

?enableWebSQL : bool

Whether to enable the WebSQL api. Default is true.

?v8CacheOptions : V8CacheOptions

Enforces the v8 code caching policy used by blink. Accepted values are

?enablePreferredSizeMode : bool

Whether to enable preferred size mode. The preferred size is the minimum size needed to contain the layout of the document—without requiring scrolling. Enabling this will cause the preferred-size-changed event to be emitted on the WebContents when the preferred size changes. Default is false.

?transparent : bool

Whether to enable background transparency for the guest page. Default is true. **Note:** 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.

?enableDeprecatedPaste : bool

Whether to enable the paste execCommand. Default is false.

Returns: WebPreferences

Instance members

Instance member Description

this.accessibleTitle

Full Usage: this.accessibleTitle

An alternative title string provided only to accessibility tools such as screen readers. This string is not directly visible to users.

this.additionalArguments

Full Usage: this.additionalArguments

A list of strings that will be appended to process.argv in the renderer process of this app. Useful for passing small bits of data down to renderer process preload scripts.

this.allowRunningInsecureContent

Full Usage: this.allowRunningInsecureContent

Allow an https page to run JavaScript, CSS or plugins from http URLs. Default is false.

this.autoplayPolicy

Full Usage: this.autoplayPolicy

Autoplay policy to apply to content in the window, can be no-user-gesture-required, user-gesture-required, document-user-activation-required. Defaults to no-user-gesture-required.

this.backgroundThrottling

Full Usage: this.backgroundThrottling

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 then frames will be drawn and swapped for the whole window and other webContents displayed by it. Defaults to true.

this.contextIsolation

Full Usage: this.contextIsolation

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 access to its own dedicated document and window globals, as well as its own set of JavaScript builtins (Array, Object, JSON, etc.), which are all invisible to the loaded content. The Electron API will only be available in the preload script and not the loaded page. This option should be used when loading potentially untrusted remote content to ensure the loaded content cannot tamper with the preload script and any Electron APIs being used. This option uses the same technique used by Chrome Content Scripts. You can access this context in the dev tools by selecting the 'Electron Isolated Context' entry in the combo box at the top of the Console tab.

this.defaultEncoding

Full Usage: this.defaultEncoding

Defaults to ISO-8859-1.

this.defaultFontFamily

Full Usage: this.defaultFontFamily

Sets the default font for the font-family.

this.defaultFontSize

Full Usage: this.defaultFontSize

Defaults to 16.

this.defaultMonospaceFontSize

Full Usage: this.defaultMonospaceFontSize

Defaults to 13.

this.devTools

Full Usage: this.devTools

Whether to enable DevTools. If it is set to false, can not use BrowserWindow.webContents.openDevTools() to open DevTools. Default is true.

this.disableBlinkFeatures

Full Usage: this.disableBlinkFeatures

A list of feature strings separated by ,, like CSSVariables,KeyboardEventKey to disable. The full list of supported feature strings can be found in the RuntimeEnabledFeatures.json5 file.

this.disableDialogs

Full Usage: this.disableDialogs

Whether to disable dialogs completely. Overrides safeDialogs. Default is false.

this.disableHtmlFullscreenWindowResize

Full Usage: this.disableHtmlFullscreenWindowResize

Whether to prevent the window from resizing when entering HTML Fullscreen. Default is false.

this.enableBlinkFeatures

Full Usage: this.enableBlinkFeatures

A list of feature strings separated by ,, like CSSVariables,KeyboardEventKey to enable. The full list of supported feature strings can be found in the RuntimeEnabledFeatures.json5 file.

this.enablePreferredSizeMode

Full Usage: this.enablePreferredSizeMode

Whether to enable preferred size mode. The preferred size is the minimum size needed to contain the layout of the document—without requiring scrolling. Enabling this will cause the preferred-size-changed event to be emitted on the WebContents when the preferred size changes. Default is false.

this.enableWebSQL

Full Usage: this.enableWebSQL

Whether to enable the WebSQL api. Default is true.

this.experimentalFeatures

Full Usage: this.experimentalFeatures

Enables Chromium's experimental features. Default is false.

this.imageAnimationPolicy

Full Usage: this.imageAnimationPolicy

Specifies how to run image animations (E.g. GIFs). Can be animate, animateOnce or noAnimation. Default is animate.

this.images

Full Usage: this.images

Enables image support. Default is true.

this.javascript

Full Usage: this.javascript

Enables JavaScript support. Default is true.

this.minimumFontSize

Full Usage: this.minimumFontSize

Defaults to 0.

this.navigateOnDragDrop

Full Usage: this.navigateOnDragDrop

Whether dragging and dropping a file or link onto the page causes a navigation. Default is false.

this.nodeIntegration

Full Usage: this.nodeIntegration

Whether node integration is enabled. Default is false.

this.nodeIntegrationInSubFrames

Full Usage: this.nodeIntegrationInSubFrames

Experimental option for enabling Node.js support in sub-frames such as iframes and child windows. All your preloads will load for every iframe, you can use process.isMainFrame to determine if you are in the main frame or not.

this.nodeIntegrationInWorker

Full Usage: this.nodeIntegrationInWorker

Whether node integration is enabled in web workers. Default is false. More about this can be found in Multithreading.

this.offscreen

Full Usage: this.offscreen

Whether to enable offscreen rendering for the browser window. Defaults to false. See the offscreen rendering tutorial for more details.

this.partition

Full Usage: this.partition

Sets the session used by the page according to the session's partition string. If partition starts with persist:, the page will use a persistent session available to all pages in the app with the same partition. If there is no persist: prefix, the page will use an in-memory session. By assigning the same partition, multiple pages can share the same session. Default is the default session.

this.plugins

Full Usage: this.plugins

Whether plugins should be enabled. Default is false.

this.preload

Full Usage: this.preload

Specifies a script that will be loaded before other scripts run in the page. This script will always have access to node APIs no matter whether node integration is turned on or off. The value should be the absolute file path to the script. When node integration is turned off, the preload script can reintroduce Node global symbols back to the global scope. See example here.

this.safeDialogs

Full Usage: this.safeDialogs

Whether to enable browser style consecutive dialog protection. Default is false.

this.safeDialogsMessage

Full Usage: this.safeDialogsMessage

The message to display when consecutive dialog protection is triggered. If not defined the default message would be used, note that currently the default message is in English and not localized.

this.sandbox

Full Usage: this.sandbox

If set, this will sandbox the renderer associated with the window, making it compatible with the Chromium OS-level sandbox and disabling the Node.js engine. This is not the same as the nodeIntegration option and the APIs available to the preload script are more limited. Default is true since Electron 20. The sandbox will automatically be disabled when nodeIntegration is set to true. Read more about the option here.

this.scrollBounce

Full Usage: this.scrollBounce

⚠ OS Compatibility: WIN ❌ | MAC ✔ | LIN ❌ | MAS ❌ Enables scroll bounce (rubber banding) effect on macOS. Default is false.

this.session

Full Usage: this.session

Sets the session used by the page. Instead of passing the Session object directly, you can also choose to use the partition option instead, which accepts a partition string. When both session and partition are provided, session will be preferred. Default is the default session.

this.spellcheck

Full Usage: this.spellcheck

Whether to enable the builtin spellchecker. Default is true.

this.textAreasAreResizable

Full Usage: this.textAreasAreResizable

Make TextArea elements resizable. Default is true.

this.transparent

Full Usage: this.transparent

Whether to enable background transparency for the guest page. Default is true. Note: 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.

this.v8CacheOptions

Full Usage: this.v8CacheOptions

Enforces the v8 code caching policy used by blink. Accepted values are

this.webSecurity

Full Usage: this.webSecurity

When false, it will disable the same-origin policy (usually using testing websites by people), and set allowRunningInsecureContent to true if this options has not been set by user. Default is true.

this.webgl

Full Usage: this.webgl

Enables WebGL support. Default is true.

this.webviewTag

Full Usage: this.webviewTag

Whether to enable the tag. Defaults to false. Note: The preload script configured for the will have node integration enabled when it is executed so you should ensure remote/untrusted content is not able to create a tag with a possibly malicious preload script. You can use the will-attach-webview event on webContents to strip away the preload script and to validate or alter the 's initial settings.

this.zoomFactor

Full Usage: this.zoomFactor

The default zoom factor of the page, 3.0 represents 300%. Default is 1.0.

Type something to start searching.