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 checkrequestNotificationPermission()โ asks the user for notification permissionshowNotification(title, options?)โ shows a notification if permission is already grantednotifyIfPermitted(title, options?)โ requests permission if needed, then shows a notification
See the API reference for full signatures.