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

前端 未结 4 1226
忘了有多久
忘了有多久 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]
    
    0 讨论(0)
  • 2020-12-01 19:24

    The Firebase SDK attempts to register the service worker at a specific location.

    The location is + /firebase-messaging-sw.js. There are two options:

    1.) Make + /firebase-messaging-sw.js work in the browser (i.e. make sure it returns a valid response) and then try using the SDK again (it should work if the browser can access the file).

    2.) Use the useServiceworker(<service worker registration>) method to pass in a custom service worker. This will still require you to have a valid service worker URL.

    0 讨论(0)
  • 2020-12-01 19:25

    Just create an empty file in root folder firebase-messaging-sw.js

    0 讨论(0)
  • 2020-12-01 19:26

    Check your angular cli file ... add

    "firebase-messaging-sw.js", "manifest.json"

    "assets": [ "assets", "app/main/content/components/angular-material", "favicon.ico", "firebase-messaging-sw.js", "manifest.json" ],

    0 讨论(0)
提交回复
热议问题