Skip to main content

Documentation 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.

WebviewJS exposes a native desktop notification API that mirrors the familiar browser Notification interface. Under the hood it uses notify-rust, which delegates to each platform’s native notification system — macOS User Notifications, Windows Toast, or Linux/XDG D-Bus. Because WebviewJS runs as a native application rather than a sandboxed browser page, permission is always granted and requestPermission() is a no-op compatibility stub. Notifications can carry action buttons, inline images, and rich lifecycle event callbacks.
Android and iOS expose the full JavaScript Notification API for source compatibility, but do not display a notification or emit native lifecycle events on those platforms.

Permissions

import { Notification } from '@webviewjs/webview';

console.log(Notification.permission); // "granted" — always
await Notification.requestPermission(); // "granted" — never prompts
Notification.permission is always "granted" for native desktop applications. requestPermission() exists solely for code that was written against the browser Web Notification API and returns immediately without prompting the user.

Constructor

new Notification(title: string, options?: NotificationOptions)
title
string
required
The heading text displayed prominently at the top of the notification.
options
NotificationOptions
Optional configuration for the notification body, icon, actions, and behaviour.
A non-empty actions array requires persistent: true. Without it the constructor throws a TypeError. On platforms where notify-rust cannot close a notification programmatically, calling close() will not release the persistent keep-alive.

Static Members

Notification.permission

permission
"granted"
Always "granted" — native applications are never subject to browser permission gates.

Notification.requestPermission()

returns
Promise<"granted">
Resolves immediately with "granted". Provided for compatibility with browser-targeted code.

Instance Properties (readonly)

All constructor options are preserved as readonly instance properties.
PropertyTypeDescription
titlestringNotification heading
bodystringBody text
iconstringIcon path or platform name
imagestring | BufferInline image
badgestringBadge icon
tagstringGrouping tag
dataunknownApplication-defined data
dir"auto" | "ltr" | "rtl"Text direction
langstringLanguage tag
renotifybooleanRe-alert on same tag
requireInteractionbooleanPersist until interaction
persistentbooleanKeep process alive
actionsNotificationAction[]Action buttons
silentbooleanSuppress sound
timestampnumberEvent timestamp (ms)
vibratenumber | number[]Vibration pattern

Event Handler Properties

Assign functions directly for a familiar DOM-style interface:
notification.onclick  = (event) => { /* ... */ };
notification.onclose  = (event) => { /* ... */ };
notification.onerror  = (event) => { /* ... */ };
notification.onshow   = (event) => { /* ... */ };

Methods

close()

Programmatically dismisses the notification where the platform supports it. Currently available through the Linux/XDG backend via notify-rust. On Windows and macOS the call is safe but performs no native close operation.

on(event, listener)

event
NotificationEventName
required
One of "click", "close", "error", or "show".
listener
(event: NotificationEvent) => void
required
Callback invoked when the event fires.
returns
this
The Notification instance, for chaining.

Events

Notification implements TypedEventEmitter<NotificationEventMap>. The full EventEmitter surface (on, once, off, addListener, removeListener, removeAllListeners, listenerCount, etc.) is available.
EventTriggerNotes
showNative backend accepted the notificationMay fire before the notification is visually displayed
clickUser activated the notification or an action buttonevent.action contains the action ID, or "" for default activation
closeBackend reported dismissal, expiry, or native closure
errorDisplay or response handling failedevent.error is an Error instance

NotificationEvent

type
NotificationEventName
The event name: "click", "close", "error", or "show".
target
Notification
The Notification instance that emitted the event.
action
string | undefined
For click events: the action identifier of the button clicked, or "" for a default (body) click. undefined for other event types.
error
Error | undefined
For error events: the underlying error. undefined for other event types.
On Windows, WebviewJS checks the global toast notification setting before submission. If notifications are disabled in Windows Settings, the instance emits error instead of show. Other OS-level policies such as Do Not Disturb can still suppress presentation after the native backend accepts a notification.

Platform Notes

Uses the macOS User Notifications framework. requireInteraction keeps the notification banner on screen. Temporary PNG files are written for image buffers and cleaned up automatically.
Uses the Windows Toast notification system. WebviewJS checks the global toast setting before submission and emits error if notifications are disabled in Windows Settings. Temporary PNG files are written for image buffers.
Uses the XDG/D-Bus notification protocol. Decoded image pixels are sent directly to the notification server. close() is functional on this platform. Exact appearance depends on the desktop environment and notification daemon.
The JavaScript API is fully exposed for source compatibility, but no notification is displayed and no lifecycle events are emitted.

Examples

import { Notification } from '@webviewjs/webview';

const notification = new Notification('Build complete', {
  body: 'The release executable is ready.',
  icon: './assets/app.png',
  requireInteraction: true,
});

notification.on('show',  ()          => console.log('notification shown'));
notification.on('click', ()          => console.log('notification clicked'));
notification.on('close', ()          => console.log('notification closed'));
notification.on('error', ({ error }) => console.error('notification error:', error));

Build docs developers (and LLMs) love