Skip to main content
Webview controls the embedded browser view attached to a BrowserWindow. You create a Webview by calling win.createWebview(options) on an existing window. Each window can host one or more webviews, and a webview can display any URL, inline HTML, or content served by a custom protocol.
Keep the Webview wrapper available for as long as you need to call its methods or listen to its events. The application and owning window retain the native view and dispose it during app.exit().
Calling new Webview() directly is not supported. Create webviews through a BrowserWindow.

Creation Options

Pass a WebviewOptions object to win.createWebview().
For a normal top-level webview on Windows and Linux, omit x, y, width, and height so the view fills the window and follows its size. A child: true view or any explicit bound opts into bounds mode; omitted positions default to 0, and omitted dimensions default to 800 × 600. On macOS, the native implementation builds every webview as a child view and derives initial bounds from the host window when you omit them.The native constructor receives the initial width and height as a physical size. Runtime setBounds() and the bounds getters use the backend’s logical geometry, so use setBounds() when you need logical child-view positioning or resizing.

Load new content or refresh the current page at any time:
HeaderData shape:
On Windows, registered custom-protocol URLs are normalized to a WebView2-compatible localhost URL by default. Set autoNormalizeLoadUrl: false to disable that behavior, or set useHttpsScheme: true to use the HTTPS form of the workaround. When you provide navigationHandler in the creation options, WebviewJS calls it synchronously before every navigation attempt. Return true to allow navigation or false to block it.
Keep navigationHandler fast and do not return a Promise. The handler runs synchronously on the browser thread. A navigation event is always emitted regardless of whether navigation is allowed or cancelled.

Script Execution

Run JavaScript in the page context:

Webview Events

Webview extends Node.js EventEmitter. Use .on(), .once(), .off(), .addListener(), .removeListener(), and .removeAllListeners() to manage listeners.

Event reference

Download events are observational — you cannot cancel a download from these events. On Windows, the new-window listener is observational; navigationHandler is still evaluated separately when you provide one.

Usage example


IPC

The page sends a message to Node by calling window.ipc.postMessage(body). Register a handler in Node with:
IpcMessage shape:
Set ipcName: 'bindings' in WebviewOptions to also expose window.bindings as an alias for window.ipc. The default window.ipc global is always available. See the IPC Messaging guide for a complete walkthrough.

expose()

expose() is a higher-level IPC helper that makes Node.js values and functions available as a named global in the page. Every exposed function becomes a Promise-returning stub in the browser, even if the Node.js implementation is synchronous.

Example

In the page:

Rules and limitations

  • Only enumerable own data properties of target are exposed. Getters, setters, and inherited properties are ignored.
  • Enumerable own data properties whose values are functions become async page functions; other exposed property values are serialized with JSON.stringify. Cyclic structures, BigInt, Symbol, and an undefined top-level value throw a SerializationError. Map and Set follow normal JSON.stringify behavior, usually becoming {}; nested undefined properties are omitted.
  • The namespace name must be a valid JavaScript identifier and can only be exposed once per webview.
See the IPC guide for more detail and the runnable expose example.
Read and write the webview’s cookie store:
WebviewCookie shape:
Use "strict", "lax", or "none" for sameSite. The native mapping treats any other value as "lax".

DevTools

Open, close, or check the browser developer tools:
DevTools must be enabled at creation time via enableDevtools: true in WebviewOptions.

Appearance

Set the background color shown before (or behind) page content. Each component is an integer in the range 0–255:

Focus

Control which element holds keyboard input:

Bounds

For child or explicitly bounded webviews, you can reposition or resize the view at runtime without recreating it.
Bounds methods are most useful for child webviews created with child: true. A top-level webview created without explicit bounds tracks the host window size automatically.
The application’s window-resize handler currently reapplies the full client rectangle to every tracked webview. If a child or explicitly bounded view must keep a sub-rectangle after its host window is resized, call setBounds() again from the window’s resize listener.

Disposal

Call webview.dispose() to release a webview before app.exit():
You can also use the using declaration for automatic cleanup:
Disposal is idempotent — calling it more than once is safe. app.exit() also disposes every webview created under that application. Disposing the parent BrowserWindow also disposes all its webviews.