Skip to main content

BrowserView

History
Version(s)Changes
>=29.0.0
API DEPRECATED
note

The BrowserView class is deprecated, and replaced by the new WebContentsView class.

A BrowserView can be used to embed additional web content into a BrowserWindow. It is like a child window, except that it is positioned relative to its owning window. It is meant to be an alternative to the webview tag.

Class: BrowserView

History
Version(s)Changes
>=29.0.0
API DEPRECATED

Create and control views.

note

The BrowserView class is deprecated, and replaced by the new WebContentsView class.

Process: Main

This module cannot be used until the ready event of the app module is emitted.

warning

Electron's built-in classes cannot be subclassed in user code. For more information, see the FAQ.

Example

// In the main process.
const { app, BrowserView, BrowserWindow } = require('electron')

app.whenReady().then(() => {
const win = new BrowserWindow({ width: 800, height: 600 })

const view = new BrowserView()
win.setBrowserView(view)
view.setBounds({ x: 0, y: 0, width: 300, height: 300 })
view.webContents.loadURL('https://electronjs.org')
})

new BrowserView([options]) Experimental Deprecated

History
Version(s)Changes
>=29.0.0
API DEPRECATED
  • options Object (optional)
    • webPreferences WebPreferences (optional) - Settings of web page's features.
      • devTools boolean (optional) - Whether to enable DevTools. If it is set to false, can not use BrowserWindow.webContents.openDevTools() to open DevTools. Default is true.
      • nodeIntegration boolean (optional) - Whether node integration is enabled. Default is false.
      • nodeIntegrationInWorker boolean (optional) - Whether node integration is enabled in web workers. Default is false. More about this can be found in Multithreading.
      • nodeIntegrationInSubFrames boolean (optional) - 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 (optional) - 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 boolean (optional) - 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 (optional) - 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 (optional) - 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 number (optional) - The default zoom factor of the page, 3.0 represents 300%. Default is 1.0.
      • javascript boolean (optional) - Enables JavaScript support. Default is true.
      • webSecurity boolean (optional) - When false, it will disable the same-origin policy (usually using testing websites by people), and set allowRunningInsecureContent to true if this option has not been set by user. Default is true.
      • allowRunningInsecureContent boolean (optional) - Allow an https page to run JavaScript, CSS or plugins from http URLs. Default is false.
      • images boolean (optional) - Enables image support. Default is true.
      • imageAnimationPolicy string (optional) - Specifies how to run image animations (E.g. GIFs). Can be animate, animateOnce or noAnimation. Default is animate.
      • textAreasAreResizable boolean (optional) - Make TextArea elements resizable. Default is true.
      • webgl boolean (optional) - Enables WebGL support. Default is true.
      • plugins boolean (optional) - Whether plugins should be enabled. Default is false.
      • experimentalFeatures boolean (optional) - Enables Chromium's experimental features. Default is false.
      • scrollBounce boolean (optional) macOS - Enables scroll bounce (rubber banding) effect on macOS. Default is false.
      • enableBlinkFeatures string (optional) - 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 (optional) - 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 Object (optional) - Sets the default font for the font-family.
        • standard string (optional) - Defaults to Times New Roman.
        • serif string (optional) - Defaults to Times New Roman.
        • sansSerif string (optional) - Defaults to Arial.
        • monospace string (optional) - Defaults to Courier New.
        • cursive string (optional) - Defaults to Script.
        • fantasy string (optional) - Defaults to Impact.
        • math string (optional) - Defaults to Latin Modern Math.
      • defaultFontSize Integer (optional) - Defaults to 16.
      • defaultMonospaceFontSize Integer (optional) - Defaults to 13.
      • minimumFontSize Integer (optional) - Defaults to 0.
      • defaultEncoding string (optional) - Defaults to ISO-8859-1.
      • backgroundThrottling boolean (optional) - 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 Object | boolean (optional) - Whether to enable offscreen rendering for the browser window. Defaults to