So basically I have button which when clicked will trigger a call to Notification.requestPermission and depending on the users response I do some action.
The issue is that Notification.requestPermission does not actually fire when it is automatically blocked by Chrome.
This is my code
function askNotificationPermission(handler) {
// checks to see if notification is actually supported
function checkNotificationPromise() {
try {
// checks if promise based notification is okay
Notification.requestPermission().then();
} catch(e) {
return false;
}
return true;
}
// Let's check if the browser supports notifications
if (!('Notification' in window)) {
console.log("This browser does not support notifications.");
} else {
if(checkNotificationPromise()) {
window.console.log("requesting permission...")
Notification.requestPermission()
.then((permission) => {
window.console.log("PERMISSION", permission)
handler(permission);
window.console.log("finished handler")
})
window.console.log("done", Notification.permission)
} else {
Notification.requestPermission(function(permission) {
handler(permission);
});
}
}
}
Is there anyway to catch when notifications are automatically blocked?