Inter-process communication in WebviewJS is built on theDocumentation 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.
window.ipc global that wry automatically injects into every page. Messages travel in both directions: the page posts raw bytes to Node with window.ipc.postMessage(), and Node pushes JavaScript expressions back into the page with evaluateScript() or reads return values with evaluateScriptWithCallback(). For structured, Promise-based two-way calls the higher-level webview.expose() API wraps all of that boilerplate behind typed namespaces that look like ordinary async functions from the page’s perspective.
Basic IPC
Create a webview with HTML content
Pass an
html string (or a url) to createWebview. The page does not need any special setup — wry injects window.ipc before any script runs.Listen for messages in Node
webview.onIpcMessage() fires for every message posted by the page. The message.body property is a Buffer — call .toString('utf8') to read it as text.Post a message from the page
Inject a script after the webview is ready, or include it in your HTML. The page calls
window.ipc.postMessage(string) to send a message to Node.On Windows, IPC only works reliably when the page is loaded through a custom protocol (e.g.
app://localhost/). Loading a file: URL on Windows will prevent window.ipc from functioning correctly.Custom IPC Global Name
By default wry injects the IPC object aswindow.ipc. Pass the ipcName option to createWebview to register an additional alias on window. Both window.ipc and your custom name remain available simultaneously.
<script> tags in the initial HTML as well as dynamically loaded modules.
Node to Page: evaluateScript and evaluateScriptWithCallback
UseevaluateScript() to push changes into the page at any time — DOM updates, data bindings, or state notifications. The call is fire-and-forget.
evaluateScriptWithCallback() when you need a return value. The expression result is serialized to JSON and delivered to the callback as a string.
JSON Messages Pattern
IpcMessage.body is raw bytes. JSON is the conventional encoding for structured payloads: stringify on the page side, parse on the Node side.
If you find yourself implementing request/response correlation on top of raw JSON messages, switch to
webview.expose() instead — it handles all of that automatically with full TypeScript types.webview.expose(): Typed Promise-Based Namespaces
webview.expose(name, target) is the recommended way to bridge Node capabilities into the page. It injects a JavaScript namespace on window[name] that mirrors the shape of target:
- Static JSON values (strings, numbers, booleans, objects, arrays) become read-only properties on the namespace.
- Functions (including
asyncfunctions) become async stubs that return aPromiseon the page side.
In-Page Usage
The page accesses static values and calls async functions throughwindow.native:
Full expose example from the source
Full expose example from the source
The
expose.mjs example in the repository combines a custom protocol for file serving with a typed native namespace:SerializationError
All values passed toexpose() — both statics and function return values — must be JSON-serializable. Passing a Buffer, Date, Map, class instance, circular reference, or any value that JSON.stringify cannot handle throws a SerializationError.
ExposedTarget Type Reference
expose() must be either a JsonValue or a callable function. Nested objects inside static values are fine as long as the whole tree is JSON-serializable.