-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnotifications.js
More file actions
34 lines (31 loc) · 1.2 KB
/
notifications.js
File metadata and controls
34 lines (31 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const runPushNotifications = async () => {
const reg = await navigator.serviceWorker.getRegistration();
if ('showTrigger' in Notification.prototype) {
alert('notifications work')
} else {
alert('no')
console.log(Notification.prototype)
}
Notification.requestPermission().then(permission => {
if (permission !== 'granted') {
alert('you need to allow push notifications');
} else {
const timestamp = new Date().getTime() + 10 * 1000; // now plus 5000ms
console.log(timestamp)
reg.showNotification(
'Demo Push Notification',
{
tag: timestamp, // a unique ID
body: 'Hello World', // content of the push notification
showTrigger: new TimestampTrigger(timestamp), // set the time for the push notification
data: {
url: window.location.href, // pass the current url to the notification
},
badge: './assets/badge.png',
icon: './assets/icon.png',
}
);
}
});
};
runPushNotifications()