-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
37 lines (33 loc) · 1.1 KB
/
index.js
File metadata and controls
37 lines (33 loc) · 1.1 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
35
36
37
(() => {
const displayError = (err) => {
message.innerHTML = `<strong>"${err}"</strong> is not defined`;
}
const browserSupportsPush = () => {
if (!('PushManager' in window)) {
displayError('window.PushManager');
return false;
}
if (!('serviceWorker' in navigator)) {
displayError('navigator.serviceWorker');
return false;
}
if (!('Notification' in window)) {
displayError('window.Notification');
return false;
}
return true;
}
const status = document.getElementById('status');
const message = document.getElementById('message');
if (browserSupportsPush() === true) {
try {
Notification.requestPermission()
status.innerHTML = `This browser supports push notifications.`;
message.innerHTML = `Status: ${Notification.permission}`;
} catch (error) {
status.innerHTML = error;
}
} else {
status.innerHTML = 'Push notifications are not supported by this browser.';
}
})()