Skip to content

Commit 55f56d3

Browse files
committed
Add service worker
1 parent 421e24b commit 55f56d3

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/serviceWorker.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
self.addEventListener('push', function (event) {
2+
if (!(self.Notification && self.Notification.permission === 'granted')) {
3+
return;
4+
}
5+
6+
const sendNotification = body => {
7+
// you could refresh a notification badge here with postMessage API
8+
const title = "Web Push example";
9+
10+
return self.registration.showNotification(title, {
11+
body,
12+
});
13+
};
14+
15+
if (event.data) {
16+
const message = event.data.text();
17+
event.waitUntil(sendNotification(message));
18+
}
19+
});

0 commit comments

Comments
 (0)