Firebase Service worker not found while using GWT (404 Error)

前端 未结 4 1242
忘了有多久
忘了有多久 2020-12-01 18:41

I\'d like to use the firebase cloud messaging service in my GWT webapplication, but I\'m stuck with some problems. The application should be able to register the firebase se

4条回答
  •  星月不相逢
    2020-12-01 19:13

    Not only a empty file, is a good idea to add the content like:

        importScripts('https://www.gstatic.com/firebasejs/7.14.2/firebase-app.js');
    importScripts('https://www.gstatic.com/firebasejs/7.14.2/firebase-messaging.js');
    /*Update this config*/
    var config = {
        apiKey: "",
        authDomain: "",
        databaseURL: "",
        projectId: "",
        storageBucket: "",
        messagingSenderId: ""
      };
      firebase.initializeApp(config);
    
    const messaging = firebase.messaging();
    messaging.setBackgroundMessageHandler(function(payload) {
      console.log('[firebase-messaging-sw.js] Received background message ', payload);
      // Customize notification here
      const notificationTitle = payload.data.title;
      const notificationOptions = {
        body: payload.data.body,
        icon: 'http://localhost/gcm-push/img/icon.png',
        image: 'http://localhost/gcm-push/img/d.png'
      };
    
      return self.registration.showNotification(notificationTitle,
          notificationOptions);
    });
    // [END background_handler]
    

提交回复
热议问题