I'm trying to push notifications to a mobile browser. I followed the documentation from https://developer.mozilla.org/en-US/docs/Web/API/Notifications_API/Using_the_Notifications_API
It's working on Chrome on desktop, but it is not working on mobile, even though the documentation says it should. I also tried this example https://jsbin.com/ziwod/2/edit?html,js,output as well but it still does not work.
Below you can find my code:
<script type="text/javascript">
createNotification("Reminder", "TEST", [100, 0, 200])
function createNotification(text_before, title, vibration) {
// Let's check if the browser supports notifications
if (!("Notification" in window)) {
alert("This browser does not support system notifications");
}
// Let's check whether notification permissions have already been granted
else if (Notification.permission === "granted") {
// If it's okay let's create a notification
var notification = new Notification(text_before, { body: title, vibrate: vibration });
}
// Otherwise, we need to ask the user for permission
else if (Notification.permission !== 'denied') {
Notification.requestPermission(function (permission) {
// If the user accepts, let's create a notification
if (permission === "granted") {
var notification = new Notification(text_before, { body: title, vibrate: vibration });
}
});
}
}
</script>
This works on desktop, but not on mobile. Thank you for your time!