Skip to main content
The Notification class provides a browser-compatible API for native desktop notifications, backed by notify-rust. You can create and listen to notifications using the same patterns you would in a browser service worker — but running entirely in your Node.js process.
The WebviewJS Notification API is intentionally API-compatible with the Web Notifications API. Existing code targeting the browser Notification constructor works with minimal changes.

Basic usage

The simplest notification requires only a title:

Constructor

The notification is dispatched to the native backend immediately on construction. There is no separate .show() call.

NotificationOptions


Icon and image

icon

The icon field accepts either a platform icon name or a file path:
  • Platform icon name — on Linux you can pass a freedesktop.org icon name such as 'dialog-information' or 'mail-unread'. The notification server resolves it from the current icon theme.
  • File path — an absolute or relative path to an image file on disk.

image

The image field displays a larger inline image and accepts either a file path string or a Buffer of encoded image bytes. Loading from a Buffer is convenient when you already have the image in memory:
Supported image formats when using a Buffer: PNG, JPEG, WebP, GIF, BMP, ICO, TIFF, and other common raster formats. If the Buffer contains invalid or unrecognisable image data, the notification emits an error event instead of show and is not displayed. Platform delivery:
  • Linux — decoded pixel data is sent directly to the notification server over D-Bus.
  • Windows / macOS — WebviewJS writes a temporary PNG file (because the native backends require a file path) and removes it when the notification lifecycle ends.
Remote URL strings are not fetched automatically. If your image is hosted remotely, download it into a Buffer first using fetch() or the node:https module, then pass the buffer.

Persistent notifications and actions

By default, notifications are non-persistent: their native callbacks do not keep the Node.js process alive. Set persistent: true when the notification must remain interactive after the rest of your application has finished running.
Rules:
  • A non-empty actions array requires persistent: true. Passing actions without persistent: true throws a TypeError.
  • A default click (body tap, no button) emits action: "" in the click event payload.
  • Clicking a named action emits action: "<your-action-identifier>".
Because WebviewJS has no service worker to restart, a persistent notification holds the Node.js event loop open until the native backend reports an interaction or closure. On platforms where the native backend cannot programmatically close a notification, calling notification.close() cannot release that hold.

Notification events

Notification instances are EventEmitters. You can use on(), once(), and off(), or assign the shorthand property handlers directly.
The action field in a click payload is:
  • "" — the notification body was clicked (default activation).
  • "<action>" — the action identifier of the button that was clicked.
Windows note: WebviewJS checks the global toast-notification setting before submission. If the user has disabled notifications in Windows Settings, the instance emits error instead of show. Other policies such as Do Not Disturb can still suppress presentation after the backend has accepted the notification.

Closing programmatically

Programmatic closure is supported on the Linux/XDG D-Bus backend. On other platforms the call is safe but performs no native close operation; the notification remains visible until it times out or the user dismisses it.

Permissions

Native application notifications do not use the browser permission model. Permission is always 'granted':
Notification.requestPermission() is a JavaScript compatibility stub. It resolves immediately with 'granted' and never prompts the user.

Platform notes