Aller au contenu principal


A View that displays a WebContents.

Process: Main

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

const { BaseWindow, WebContentsView } = require('electron')
const win = new BaseWindow({ width: 800, height: 400 })

const view1 = new WebContentsView()
view1.setBounds({ x: 0, y: 0, width: 400, height: 400 })

const view2 = new WebContentsView()
view2.setBounds({ x: 400, y: 0, width: 400, height: 400 })

Class: WebContentsView extends View

A View that displays a WebContents.

Process: Main

WebContentsView inherits from View.

WebContentsView is an EventEmitter.

new WebContentsView([options])

  • options Object (optional)
    • webPreferences WebPreferences (optional) - Settings of web page's features.

Creates an empty WebContentsView.

Propriétés d'instance

Objects created with new WebContentsView have the following properties, in addition to those inherited from View:

view.webContents Readonly

A WebContents property containing a reference to the displayed WebContents. Use this to interact with the WebContents, for instance to load a URL.

const { WebContentsView } = require('electron')
const view = new WebContentsView()