Skip to content

Instantly share code, notes, and snippets.

@dbushell
Created April 12, 2023 10:04
Show Gist options
  • Save dbushell/39e35d5fa5404dfe7b555e98f0194619 to your computer and use it in GitHub Desktop.
Save dbushell/39e35d5fa5404dfe7b555e98f0194619 to your computer and use it in GitHub Desktop.
Service Worker for Web Push API
self.addEventListener('push', (ev) => {
// https://developer.apple.com/documentation/usernotifications/sending_web_push_notifications_in_safari_and_other_browsers
// >> Safari doesn’t support invisible push notifications.
// >> Present push notifications to the user immediately after your service worker receives them.
// >> If you don’t, Safari revokes the push notification permission for your site.
ev.waitUntil(
self.registration.showNotification('Push Message', {
body: ev.data?.text() ?? 'no data'
})
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment