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.
Always store BrowserWindow and Webview instances in variables that live as long as you need them. If you let these references be garbage-collected, the native handles become unreachable and their event listeners stop firing.
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:
Without the application-close-requested handler calling app.exit(), the process stays alive after the last window closes because the event pump timer keeps Node running.
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:
Values, arguments, and return types 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 distributable single-file binary.