Documentation Index
Fetch the complete documentation index at: https://mintlify.com/webviewjs/webview/llms.txt
Use this file to discover all available pages before exploring further.
Webview is the embedded browser surface attached to a BrowserWindow. You create it by calling win.createWebview() after the application is ready. Once created, a webview gives you full control over page navigation, JavaScript execution, two-way IPC messaging, cookie management, DevTools access, and layout positioning. The native webview lifetime is owned by the root Application — keep a JavaScript reference to the Webview wrapper for as long as you need to interact with it.
Creation Options
Pass these towin.createWebview(options):
URL to load when the webview is created. Mutually exclusive with
html.Inline HTML string to render. Mutually exclusive with
url.Left offset in logical pixels from the window’s top-left corner. Child webviews only.
Top offset in logical pixels from the window’s top-left corner. Child webviews only.
Width in logical pixels. Child webviews only.
Height in logical pixels. Child webviews only.
When
true, the webview is positioned relative to the parent window using x/y/width/height instead of filling the full window area.Enable the built-in DevTools panel.
Make the webview background transparent. The window must also be transparent.
Private/incognito mode — no cookies, cache, or storage are persisted between sessions.
Override the browser’s
User-Agent header string.JavaScript source string injected into every page before any page scripts run. Use for setting up globals, polyfills, or IPC bridges.
Custom name for the IPC global (default:
"ipc", i.e. window.ipc). Pass "bindings" to expose window.bindings as an alias alongside the default window.ipc.A
WebContext created via app.createWebContext(). Webviews sharing the same context share cookies, cache, local storage, and IndexedDB. See WebContext reference.Synchronous navigation guard called before every navigation. Return
true to allow, false to cancel. Keep this callback fast — do not return a Promise. A navigation event is always emitted regardless of the handler’s return value.Override the preferred color scheme.
Theme.Light (0), Theme.Dark (1), or Theme.System (2).Allow pinch-to-zoom and keyboard zoom shortcuts inside the webview.
Enable clipboard access from page JavaScript.
Allow media autoplay without user interaction.
Enable swipe-back / swipe-forward navigation gestures (macOS and iOS).
For top-level webviews, omit
x/y/width/height so the view automatically fills the window and resizes with it. Setting explicit bounds on a top-level webview causes a black-border artifact when the window is maximised.Navigation
loadUrl(url)
loadHtml(html)
loadUrlWithHeaders(url, headers)
URL to navigate to.
Additional HTTP request headers as
{ key: string, value?: string }[].reload()
url()
null if no page is loaded.
Navigation handler
Script Execution
evaluateScript(js)
evaluateScriptWithCallback(js, callback)
js and receive the serialised result (or an error) in callback. The result is always a string — parse JSON if your script returns a structured value.
preload option
JavaScript provided via the preload option is injected into every page before any of the page’s own scripts execute. Use it to define globals, mock APIs, or establish IPC channels:
IPC Messaging
onIpcMessage(handler)
Register a handler for messages sent from the page via window.ipc.postMessage(body).
Called with an
IpcMessage object for each message from the page.expose(name, target)
Expose static JSON values and async Node.js functions under a named global in the page. Page-side functions always return Promises, even if the Node.js implementation is synchronous.
Valid JavaScript identifier used as the property name on
window. Can only be exposed once per webview.A plain object whose own enumerable properties are either JSON-serialisable values or async functions. Getters, setters, and non-enumerable properties are ignored.
Cookies & Storage
getCookies(url?)
url when provided.
setCookie(cookie)
deleteCookie(name, domain?, path?)
domain and/or path to narrow the match; omit them to delete across all domains and paths.
clearAllBrowsingData()
DevTools
DevTools must be enabled at creation time via
enableDevtools: true in WebviewOptions. Calling openDevtools() on a webview created without this option has no effect.Layout & Bounds
For top-level webviews (the default), the view fills the window automatically and resizes with it — do not callsetBounds. For child webviews (child: true), you control the position and size explicitly.
getBounds()
{ x: number, y: number, width: number, height: number } — all in logical pixels relative to the window’s top-left corner.setBounds(bounds)
Dimension getters (logical pixels)
null is returned when the property is not applicable (e.g. top-level webview without explicit bounds).
setWebviewVisibility(visible)
Focus
Appearance
setBackgroundColor(r, g, b, a)
0–255.
zoom(scaleFactor)
1.0 is 100%; 1.5 is 150%.
print()
Events
Webview implements the standard Node.js EventEmitter interface — on, once, off, addListener, removeListener, and removeAllListeners are all available.
| Event | Payload | Description |
|---|---|---|
page-load-started | { event, url? } | Navigation has committed and the page has begun loading |
page-load-finished | { event, url? } | Page has fully loaded (including subresources) |
title-changed | { event, title? } | The document <title> changed |
download-started | { event, url? } | A file download has begun |
download-completed | { event, url?, success? } | A download finished (success: true) or failed (success: false) |
navigation | { event, url? } | A navigation was attempted (fired even if cancelled by navigationHandler) |
new-window | { event, url? } | Page requested a new window via window.open or target="_blank" |
Download events are observational — they do not provide a mechanism to cancel downloads. The
new-window event is also observational on Windows, where Wry dispatches it from a separate WebView2 thread.Custom Protocols
Custom protocol handlers are registered on theBrowserWindow, not the Webview, and must be registered before calling createWebview():
Disposal
webview.dispose() for early cleanup. Disposal is idempotent — calling it twice is safe. webview.isDisposed() reports the current state. Disposing the parent BrowserWindow or calling app.exit() also disposes every webview automatically.