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:
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.
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. Setpersistent: true when the notification must remain interactive after the rest of your application has finished running.
- A non-empty
actionsarray requirespersistent: true. Passing actions withoutpersistent: truethrows aTypeError. - A default click (body tap, no button) emits
action: ""in the click event payload. - Clicking a named action emits
action: "<your-action-identifier>".
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>"— theactionidentifier of the button that was clicked.
error instead of show. Other policies such as Do Not Disturb can still suppress presentation after the backend has accepted the notification.
Closing programmatically
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.