FirebaseError:消息传递:我们无法注册默认服务工作者

时间:2018-10-10 12:45:23

标签: jquery firebase firebase-cloud-messaging

你好,请帮我...... 提前感谢您的回复 .................................... 授予通知权限。 ; FirebaseError:消息传递:我们无法注册默认服务工作者。无法注册ServiceWorker:获取脚本时收到错误的HTTP响应代码(404)。 (消息/服务工作人员注册失败)。

  <script src="https://www.gstatic.com/firebasejs/5.5.3/firebase-auth.js"></script>
    <script>
        MsgElem = document.getElementById("msg")
        TokenElem = document.getElementById("token")
        NotisElem = document.getElementById("notis")
        ErrElem = document.getElementById("err")
        // Initialize Firebase
        // TODO: Replace with your project's customized code snippet
         var config = {
             apiKey: "AIzaSyBle95lld9XUBB5P-sn2vFciSxcIny-RQs",
             authDomain: "swapnear-f82dd.firebaseapp.com",
             databaseURL: "https://swapnear-f82dd.firebaseio.com",
             projectId: "swapnear-f82dd",
             storageBucket: "swapnear-f82dd.appspot.com",
             messagingSenderId: "390359777744"
         };
         firebase.initializeApp(config);

        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) {
                TokenElem.innerHTML = "token is : " + token
            })
            .catch(function (err) {
                ErrElem.innerHTML =  ErrElem.innerHTML + "; " + err
                console.log("Unable to get permission to notify.", err);
            });

        messaging.onMessage(function(payload) {
            console.log("Message received. ", payload);
            NotisElem.innerHTML = NotisElem.innerHTML + JSON.stringify(payload) ;
        });
    </script>

0 个答案:

没有答案