2017-04-25 89 views
0

所以我按照這個firebase教程,似乎我根據文檔做了所有事情,但仍然出現錯誤。 Youtube FCM Tutorial無法在Webstorm上註冊服務工作人員

var config = { 
 
    apiKey: "AIzaSyAyWVXB9KFLm2ymoBoiY-TothNYgo3IrtA", 
 
    authDomain: "fir-end-cff84.firebaseapp.com", 
 
    databaseURL: "https://fir-end-cff84.firebaseio.com", 
 
    projectId: "fir-end-cff84", 
 
    storageBucket: "fir-end-cff84.appspot.com", 
 
    messagingSenderId: "297653223714" 
 
}; 
 
firebase.initializeApp(config); 
 

 
if ('serviceWorker' in navigator) { 
 
    navigator.serviceWorker.register('./firebase-messaging-sw.js').then(function (registration) { 
 
     // Registration was successful 
 
     console.log('ServiceWorker registration successful with scope: ', registration.scope); 
 
    }).catch(function (err) { 
 
     // registration failed :(
 
     console.log('ServiceWorker registration failed: ', err); 
 
    }); 
 
} 
 

 
const messaging = firebase.messaging(); 
 
messaging.requestPermission() 
 
    .then(function() { 
 
     console.log('Have Permit'); 
 
     return messaging.getToken(); 
 
    }) 
 
    .then(function (token) { 
 
     console.log(token); 
 
    }) 
 
    .catch(function (err) { 
 
     console.log(err); 
 
    })

這些日誌: enter image description here

這是項目概述:使用Ubuntu的最新版本webstorm的

enter image description here

林16.04

編輯:我竟然用這樣的回購,但仍然有同樣的問題 https://github.com/firebase/quickstart-js/tree/master/messaging

回答

0

Apperently獲得FCM令牌本地主機需要有應用服務器的功能,一些webstorm的本地主機不會做!