Skip to content

Instantly share code, notes, and snippets.

@benixal
Last active March 25, 2024 09:39
Show Gist options
  • Save benixal/80440dcec49f71c4423f428e27e7ad6f to your computer and use it in GitHub Desktop.
Save benixal/80440dcec49f71c4423f428e27e7ad6f to your computer and use it in GitHub Desktop.
Firebase Cloud Messaging (FCM) custom service worker
self.addEventListener("push", (event) => {
const notif = event.data.json().notification;
event.waitUntil(self.registration.showNotification(notif.title, {
body: notif.body,
icon: notif.image, /* or "icon.png" */
data: {
url: notif.click_action
}
}))
})
self.addEventListener("notificationclick",(event) => {
event.waitUntil(clients.openWindow(event.notification.data.url))
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment