Consider the following.
if (this.Notification) {
Notification.requestPermission(function(permission) {
if (permission === 'granted') {
return new Notification('hi this is a test');
} else {
return alert("Notifications not permitted");
}
});
} else {
alert('Notifications not supported');
}
JSFiddle.
This seems to behave as expected in Chrome on desktop. In Firefox for Android, such notifications appear in the Android notification bar.
However on Android Chrome it seems to prompt the user to allow/disallow notifications, but if the user clicks 'allow' nothing seems to happen. Does Android Chrome support this sort of notification?
EDIT: This is different to this question from 18 months ago - then window.Notification
wasn't defined at all. Now it is defined but doesn't seem to do anything.
I think this is a duplicate with the following question HTML5 Notification not working in Mobile Chrome. When I debug it on my Android device, I get the following error:
Failed to construct 'Notification': Illegal constructor. Use ServiceWorkerRegistration.showNotification()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With