Skip to content

Instantly share code, notes, and snippets.

@theory-of-soul
Created December 6, 2021 01:57
Show Gist options
  • Save theory-of-soul/55060f474d701b482b1e79008ddd73e9 to your computer and use it in GitHub Desktop.
Save theory-of-soul/55060f474d701b482b1e79008ddd73e9 to your computer and use it in GitHub Desktop.
manage click on web push message
if (firebase && firebase.messaging.isSupported()) {
const messaging = firebase.messaging();
/* eslint-disable */
messaging.onBackgroundMessage(function (payload) {
const clickUrl = payload.data["gcm.notification.url"];
const notificationTitle = payload.notification.title;
const notificationOptions = {
body: payload.notification.body,
icon: "/logo.png",
};
self.addEventListener("notificationclick", function (event) {
event.notification.close();
event.waitUntil(self.clients.openWindow(clickUrl));
});
return self.registration.showNotification(
notificationTitle,
notificationOptions
);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment