Skip to main content
In this guide you’ll install WebviewJS, open a native OS window, load content into it, react to window events, and send a message from the page back to Node.js. By the end you’ll have a working desktop app and an understanding of the core building blocks — Application, BrowserWindow, and Webview.
1

Install WebviewJS

Add the package to your project:
Make sure you have Node.js 24 or later and that your platform dependencies are satisfied. See the Installation guide for per-platform setup instructions.
2

Create your first window

Create a file called app.mjs and add the following:
app.mjs
Run it:
A native window opens and loads https://example.com. Close the window to exit.
Keep BrowserWindow and Webview wrappers in variables for as long as you need to call their methods or use their event listeners. The application owns the native resources, so garbage-collecting a wrapper does not itself dispose the native object.
3

Load local HTML

Instead of navigating to a URL, pass an html string to render content directly without a web server:
Use the html option for self-contained pages, prototypes, or any scenario where you want to serve content without a protocol handler or HTTP server.
4

Handle window events

The Application instance is a typed EventEmitter. Listen for lifecycle events to react to user actions:
The runtime shuts down automatically after the OS close request for the last tracked window. Calling app.exit() in this handler is safe and idempotent, but it is not required to stop the pump.
5

Add IPC — page to Node

The page can send messages to your Node.js code using window.ipc.postMessage(). Listen with webview.onIpcMessage():
Click the button in the window — “ping” appears in your terminal and the page updates to show “Node replied: pong”.

Going further: expose async functions

For a cleaner request/response pattern, use webview.expose() to publish an entire namespace of Node.js functions directly to the page. Every exposed function automatically becomes a Promise in the browser context:
Static exposed values, function arguments, and function return values must be JSON-serializable. Violations throw a SerializationError.

Event Loop

Understand how the non-blocking pump works and how to control it.

IPC Messaging

Deep-dive into page ↔ Node communication patterns.

API Reference — Application

Full reference for the Application class, events, and options.

Build Executables

Compile your app into a standalone executable.