0
votes

I am facing an issue while integrating with firebase, I can successfully intiatize messaging, and can show the popup to ask user for permissions to show notifications, but after that I cannot get the token for the user.

When I see the log, I notice that there is following error in console logs

firebase.initializeApp(config);
      const messaging = firebase.messaging();


      messaging.requestPermission().then(function (permission) {
        var token = messaging.getToken();
        alert(token);
        token.then(function (cToken) {
          alert(cToken);
        });
      });

core.js:15724 ERROR Error: Uncaught (in promise): FirebaseError: Messaging: We are unable to register the default service worker. Failed to register a ServiceWorker: A bad HTTP response code (404) was received when fetching the script. (messaging/failed-serviceworker-registration). FirebaseError: Messaging: We are unable to register the default service worker. Failed to register a ServiceWorker: A bad HTTP response code (404) was received when fetching the script. (messaging/failed-serviceworker-registration). at firebase.js:1 at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:391) at Object.onInvoke (core.js:17299) at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:390) at Zone.push../node_modules/zone.js/dist/zone.js.Zone.run (zone.js:150) at zone.js:910

2

2 Answers

0
votes

If you're using the angular service worker through the angular service worker package you need to register your service worker in your app.module.ts.

import { ServiceWorkerModule } from '@angular/service-worker';

and then in imports add imports: [ ServiceWorkerModule.register('ngsw-worker.js', { enabled: environment.production })]

0
votes

I have added the javascript library as follows in html file, although this is index file of angular. If you still think it is angular component which is throwing the exception please suggest corrective steps.

<script src="https://www.gstatic.com/firebasejs/5.5.9/firebase.js"></script>