Skip to main content

notifications

Request permission and show desktop notifications via the Notifications API.

Import: @rtorcato/browser-common/notifications

๐Ÿ“– MDN: Notifications API ยท ๐Ÿ“Š caniuse: notifications

Needs a secure context and user permission (requestNotificationPermission).

Exampleโ€‹

import { isNotificationAvailable, notifyIfPermitted } from '@rtorcato/browser-common/notifications'

button.addEventListener('click', async () => {
if (isNotificationAvailable()) {
await notifyIfPermitted('Done', { body: 'Upload complete' })
}
})

Exportsโ€‹

  • isNotificationAvailable() โ€” feature check
  • requestNotificationPermission() โ€” asks the user for notification permission
  • showNotification(title, options?) โ€” shows a notification if permission is already granted
  • notifyIfPermitted(title, options?) โ€” requests permission if needed, then shows a notification

See the API reference for full signatures.