Я пытался получить уведомление о работе Chrome и Brave, но при нажатии кнопки ничего не отображается.Он запрашивает разрешение в первый раз, и если я обновлю файл console.log, он покажет «предоставлено».Следовательно, должно быть возможно создать новое уведомление с конструктором new Notification();
.Проблема в том, что он просто ничего не показывает.
Я проверил настройки веб-страницы, и все должно быть хорошо.У меня такое ощущение, что поддержка Chrome больше не работает для API уведомлений.Есть ли лучший способ получать уведомления с помощью Javascript, поэтому, если определенное требование к данным выполнено, оно отображает уведомление для всех пользователей / посетителей?
И дополнительно, как получить уведомление, которое будет отображаться, даже если у вас естьзакрыл страницу?
КОД
<div class="container">
<h1>Notification Test</h1>
<button onclick="notifyMe()">I want a notification!</button>
</div>
<script>
function notifyMe(){
// Let's check if the browser supports notifications
if (!("Notification" in window)) {
alert("This browser does not support desktop notification");
}
// Let's check if the user is okay to get some notification
else if (Notification.permission === "granted") {
// If it's okay let's create a notification
var notification = new Notification("Hi there!");
notification.show();
}
// Otherwise, we need to ask the user for permission
// Note, Chrome does not implement the permission static property
// So we have to check for NOT 'denied' instead of 'default'
else if (Notification.permission !== 'denied') {
Notification.requestPermission(function (permission) {
// Whatever the user answers, we make sure we store the information
if(!('permission' in Notification)) {
Notification.permission = permission;
}
// If the user is okay, let's create a notification
if (permission === "granted") {
var notification = new Notification("Hi there!");
}
});
}
}
</script>