Skip to content

Commit 085fa6c

Browse files
committed
Extra notification check for Edge
1 parent 2596a1d commit 085fa6c

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/app.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,33 @@ document.addEventListener("DOMContentLoaded", () => {
9191
return outputArray;
9292
}
9393

94+
function checkNotificationPermission() {
95+
return new Promise((resolve, reject) => {
96+
if (Notification.permission === 'denied') {
97+
return reject(new Error('Push messages are blocked.'));
98+
}
99+
100+
if (Notification.permission === 'granted') {
101+
return resolve();
102+
}
103+
104+
if (Notification.permission === 'default') {
105+
return Notification.requestPermission().then(result => {
106+
if (result !== 'granted') {
107+
reject(new Error('Bad permission result'));
108+
}
109+
110+
resolve();
111+
});
112+
}
113+
});
114+
}
115+
94116
function push_subscribe() {
95117
changePushButtonState('computing');
96118

97-
navigator.serviceWorker.ready
119+
return checkNotificationPermission()
120+
.then(() => navigator.serviceWorker.ready)
98121
.then(serviceWorkerRegistration => serviceWorkerRegistration.pushManager.subscribe({
99122
userVisibleOnly: true,
100123
applicationServerKey: urlBase64ToUint8Array(applicationServerKey),

0 commit comments

Comments
 (0)