Skip to content

Instantly share code, notes, and snippets.

@oahehc
Created September 30, 2020 03:44
Show Gist options
  • Save oahehc/8b04c59601aba2326b1362eda03bbc36 to your computer and use it in GitHub Desktop.
Save oahehc/8b04c59601aba2326b1362eda03bbc36 to your computer and use it in GitHub Desktop.
self.addEventListener("push", (event) => {
if (event.data) {
try {
data = JSON.parse(event.data.text());
event.waitUntil(
self.registration.showNotification(data.title, {
body: data.content,
icon: "/icon-192.png",
badge: "/badge-192.png",
})
);
} catch (e) {
console.error('push event data parse fail');
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment