Reputation: 61
Web push notification is working fine when browser is open. But with browser closed not sure if notifications are queuing up or not as when its reopened the notification is not showing.
I tried to set the TTL but its still not working so I think the notifications are not getting queued when browser is closed.
Upvotes: 1
Views: 1182
Reputation: 99
You can make use of Web Periodic Background Sync API You can run this feature offline too and even app is closed, it doesn't require backend server for push as it triggers by the service worker periodically (min 24 hr I guess)
in your project files register sync event:
registration.periodicSync.register(constants.periodicBgSyncEventName, {
minInterval: syncMinInterval,
networkState: "any",
});
in your service worker file listen to the sync and show web notification:
self.addEventListener("periodicsync", (event) => {
if (event.tag === constants.periodicBgSyncEventName) {
self.registration.showNotification("Wake Time !!!", {
body: `Hi, Good Morning`,
});
}
});
Note - In order to use this Periodic Sync API you need to install the PWA first.
Upvotes: 1