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.
Create and control views.
Process: Main
// 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')
})optionsObject (optional)webPreferencesObject (optional) - See BrowserWindow.
Objects created with new BrowserView have the following properties:
A WebContents object owned by this view.
A Boolean representing whether this BrowserView receives any mouse input. Any BrowserView
with clickThrough = true will still display but won't receive any mouse events.
Objects created with new BrowserView have the following instance methods:
optionsObjectwidthboolean (optional) - Iftrue, the view's width will grow and shrink together with the window.falseby default.heightboolean (optional) - Iftrue, the view's height will grow and shrink together with the window.falseby default.horizontalboolean (optional) - Iftrue, the view's x position and width will grow and shrink proportionally with the window.falseby default.verticalboolean (optional) - Iftrue, the view's y position and height will grow and shrink proportionally with the window.falseby default.
boundsRectangleoptionsObject (optional)fromBoundsRectangle (optional) - The initial position and size of the view, relative to its parent.durationFloat (optional) - A duration of the animation (in seconds). Default is 1.0.timingFunctionstring (optional) - One of the following values:linear,easeIn,easeOut,easeInEaseOut,default. Default islinear.timingControlPointsObject (optional)x1Float (optional) - A floating point number representing the x position of the c1 control point.y1Float (optional) - A floating point number representing the y position of the c1 control point.x2Float (optional) - A floating point number representing the x position of the c2 control point.y2Float (optional) - A floating point number representing the y position of the c2 control point.
Resizes and moves the view to the supplied bounds relative to the window.
In case one of the values : duration, timingFunction, timingControlPoints is specified, the resizing / moving is animated.
It's possible to specify a function that defines the pacing of an animation as a timing curve.
The function maps an input time normalized to the range [0,1] to an output time also in the range [0,1].
You can specify a media timing function by supplying your own cubic Bézier curve control points using the timingControlPoints options or by using one of the predefined timing functions.
You can configure the timing function with the predefined timing function specified by name:
linear- Linear pacing, which causes an animation to occur evenly over its durationeaseIn- Ease-in pacing, which causes an animation to begin slowly and then speed up as it progresseseaseOut- Ease-out pacing, which causes an animation to begin quickly and then slow as it progresseseaseInEaseOut- Ease-in-ease-out pacing, which causes an animation to begin slowly, accelerate through the middle of its duration, and then slow again before completingdefault- Similar to 3t^2 - 2t^3, one of the basic Hermite blending functions.
When you supply your own cubic Bézier curve control points, then the function is modeled as a cubic Bézier curve. The end points of the Bézier curve are automatically set to (0.0,0.0) and (1.0,1.0). The control points defining the Bézier curve are: [(0.0,0.0), (c1x,c1y), (c2x,c2y), (1.0,1.0)].
Returns Rectangle
The bounds of this BrowserView instance as Object.
colorstring - Color in#aarrggbbor#argbform. The alpha channel is optional.
Makes the scaling of the view equal to the window's base coordinate system.
optionsObjectscaleXnumber (optional) - Specifies the x value for the new unit size.scaleYnumber (optional) - Specifies the y value for the new unit size.adjustFramestring (optional) - Adjusts the bounds (frame) to the scaled bounds.anchorXstring (optional) - The x coordinate of the anchor point when scaling. It can be one of the following values:left,center,right. It can be also the number between 1 and 100 (specifying the percentage).anchorYstring (optional) - The y coordinate of the anchor point when scaling. It can be one of the following values:top,center,bottom. It can be also the number between 1 and 100 (specifying the percentage).animationObject (optional)durationFloat (optional) - A duration of the animation (in seconds). Default is 1.0.timingFunctionstring (optional) - One of the following values:linear,easeIn,easeOut,easeInEaseOut,default. Default islinear.timingControlPointsObject (optional)x1Float (optional) - A floating point number representing the x position of the c1 control point.y1Float (optional) - A floating point number representing the y position of the c1 control point.x2Float (optional) - A floating point number representing the x position of the c2 control point.y2Float (optional) - A floating point number representing the y position of the c2 control point.
Scales the view’s coordinate system so that the unit square scales to the specified dimensions.
In case when animation is specified, the scaling and resizing / moving is animated.
The function does the simultaneous translation animation to keep the view's anchor during the zoom animation.
It's possible to specify a function that defines the pacing of an animation as a timing curve.
The function maps an input time normalized to the range [0,1] to an output time also in the range [0,1].
You can specify a media timing function by supplying your own cubic Bézier curve control points using the timingControlPoints options or by using one of the predefined timing functions.
You can configure the timing function with the predefined timing function specified by name:
linear- Linear pacing, which causes an animation to occur evenly over its durationeaseIn- Ease-in pacing, which causes an animation to begin slowly and then speed up as it progresseseaseOut- Ease-out pacing, which causes an animation to begin quickly and then slow as it progresseseaseInEaseOut- Ease-in-ease-out pacing, which causes an animation to begin slowly, accelerate through the middle of its duration, and then slow again before completingdefault- Similar to 3t^2 - 2t^3, one of the basic Hermite blending functions.
When you supply your own cubic Bézier curve control points, then the function is modeled as a cubic Bézier curve. The end points of the Bézier curve are automatically set to (0.0,0.0) and (1.0,1.0). The control points defining the Bézier curve are: [(0.0,0.0), (c1x,c1y), (c2x,c2y), (1.0,1.0)].
Returns the unit square scale of x dimension.
Returns the unit square scale of x dimension.
opacitynumber - between 0.0 (fully transparent) and 1.0 (fully opaque)optionsObject (optional)durationFloat (optional) - A duration of the animation (in seconds). Default is 1.0.timingFunctionstring (optional) - One of the following values:linear,easeIn,easeOut,easeInEaseOut,default. Default islinear.timingControlPointsObject (optional)x1Float (optional) - A floating point number representing the x position of the c1 control point.y1Float (optional) - A floating point number representing the y position of the c1 control point.x2Float (optional) - A floating point number representing the x position of the c2 control point.y2Float (optional) - A floating point number representing the y position of the c2 control point.
Sets the opacity of the view. Out of bound number values are clamped to the [0, 1] range.
In case one of the values : duration, timingFunction, timingControlPoints is specified, the opacity change is animated.
Returns number - between 0.0 (fully transparent) and 1.0 (fully opaque).
visibleboolean - Sets whether this view is visible.
Returns boolean - Whether the view is visible.
freezeboolean - Hides and freezes the page. A frozen page runs as few tasks as possible.thumbnailNativeImage - The thumbnail to show on top of the page.
Hides the thumbnail. If the page is hidden and frozen, then it shows the page which is automatically unfrozen.