Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 无法获得通知的权限。FirebaseError:在选择通知提示之前显示错误_Javascript_Laravel_Firebase_Notifications_Firebase Cloud Messaging - Fatal编程技术网

Javascript 无法获得通知的权限。FirebaseError:在选择通知提示之前显示错误

Javascript 无法获得通知的权限。FirebaseError:在选择通知提示之前显示错误,javascript,laravel,firebase,notifications,firebase-cloud-messaging,Javascript,Laravel,Firebase,Notifications,Firebase Cloud Messaging,无法获得通知的权限。FirebaseError:消息传递:未授予所需的权限,而是将其取消。(消息传递/权限默认设置)。在我甚至可以从通知提示符中选择选项之前显示在控制台上。通常,这个错误应该在从通知提示中选择一个选项后显示,但由于某些原因,它在我甚至可以单击提示之前显示,因此通知现在不起作用。尽管它以前工作得很完美。这段代码目前在chrome版本81.0.4044.113(官方版本)(64位)上运行良好,之前在Firefox44上运行良好 if (!("Notification" in win

无法获得通知的权限。FirebaseError:消息传递:未授予所需的权限,而是将其取消。(消息传递/权限默认设置)。在我甚至可以从通知提示符中选择选项之前显示在控制台上。通常,这个错误应该在从通知提示中选择一个选项后显示,但由于某些原因,它在我甚至可以单击提示之前显示,因此通知现在不起作用。尽管它以前工作得很完美。这段代码目前在chrome版本81.0.4044.113(官方版本)(64位)上运行良好,之前在Firefox44上运行良好

 if (!("Notification" in window)) {
console.error("Notification isn't enabled");
} else if (Notification.permission === "granted") {
console.log("Notification is enabled");
 } else if (Notification.permission !== "denied") {

 // Retrieve an instance of Firebase Messaging so that it can handle background
  // messages.
 firebase.initializeApp(firebaseConfig);
  const messaging = firebase.messaging();
  messaging
  .requestPermission()
  .then(function () {
   // MsgElem.innerHTML = "Notification permission granted." 
    //console.log("Notification permission granted.");

   // get the token in the form of promise
   return messaging.getToken()
  })
  .then(function(token) {
    // print the token on the HTML page
    //TokenElem.innerHTML = "token is : " + token
         $.ajax({
        type:'POST',
        url:'/SaveNotificationToken',
        data:{token : token, _token: "<?php echo csrf_token(); ?>",UserId:             {{auth()->user()->id}} },
        success:function(data){
            //alert(data+"You will receive notiications from clients that viewed your service ");
            $("#msg").html(data);
        }
    }); 

   })
 .catch(function (err) {
  //ErrElem.innerHTML = ErrElem.innerHTML + "; " + err
   console.log("Unable to get permission to notify.", err);
});


}
if(!(“窗口中的通知”){
console.error(“通知未启用”);
}else if(Notification.permission==“已授予”){
console.log(“通知已启用”);
}else if(Notification.permission!=“拒绝”){
//检索Firebase消息传递的实例,以便它能够处理后台消息传递
//信息。
firebase.initializeApp(firebaseConfig);
const messaging=firebase.messaging();
消息传递
.requestPermission()
.然后(函数(){
//MsgElem.innerHTML=“已授予通知权限。”
//log(“已授予通知权限”);
//以承诺的形式获得代币
返回消息。getToken()
})
.then(功能(令牌){
//在HTML页面上打印令牌
//TokenElem.innerHTML=“令牌是:”+令牌
$.ajax({
类型:'POST',
url:“/SaveNotificationToken”,
数据:{token:token,_token:,{auth()->user()->id}},
成功:功能(数据){
//警报(数据+“您将收到查看您服务的客户的通知”);
$(“#msg”).html(数据);
}
}); 
})
.catch(函数(err){
//ErrElem.innerHTML=ErrElem.innerHTML+“;”+err
log(“无法获得通知权限”,错误);
});
}