Web Notification API

Creator
Creator
Seonglae ChoSeonglae Cho
Created
Created
2021 May 23 5:10
Editor
Edited
Edited
2023 Apr 28 16:0
Refs
Refs

schedule local notifications that don't require a network connection

Notifire

create

if ('showTrigger' in Notification.prototype) { const createScheduledNotification = async (tag, title, timestamp) => { const registration = await navigator.serviceWorker.getRegistration(); registration.showNotification(title, { tag: tag, body: 'This notification was scheduled 30 seconds ago', showTrigger: new TimestampTrigger(timestamp + 30 * 1000), }); }; }
 

cancel

const cancelScheduledNotification = async (tag) => { const registration = await navigator.serviceWorker.getRegistration(); const notifications = await registration.getNotifications({ tag: tag, includeTriggered: true, }); notifications.forEach((notification) => notification.close()); };
 

demo

Notification Triggers
Notification Triggers
The Notification Triggers API allows developers to schedule local notifications that don't require a network connection, which makes them ideal for use cases like calendar apps.
Notification Triggers
 
 

Recommendations