angular / angularfire

Angular + Firebase = ❤️
https://firebaseopensource.com/projects/angular/angularfire2
MIT License
7.66k stars 2.19k forks source link

Cant get foreground notification, cant get token in chrome #2293

Closed all2pie closed 3 years ago

all2pie commented 4 years ago

I am using AngularFireMessaging and getting some issue, did a lot of research, read official docs but could not solve them.

1st issue is that when i send push notification the foreground notification handler crashes (image below), background notifications are working fine and everything is correctly setup.

image

2nd issue is that i can not get token in chrome, image below:

image

Kindly help.

Version info

Angular: 8.2.14

Firebase: 7.7.0

AngularFire: 5.3.0

all2pie commented 4 years ago

Notification Service Code:

import { Injectable } from '@angular/core';
import { AngularFireMessaging } from '@angular/fire/messaging';

@Injectable()
export class NotificationService {

  constructor(private messaging: AngularFireMessaging, private generalService: GeneralService) { }

  getPermission() {

      this.messaging.requestToken
        .subscribe(
          (token) => {
            console.log('Permission granted! Save to the server!', token);
            this.messaging.messages
              .subscribe((message) => { console.log(message); });
          },
          (error) => { console.error(error); },
        );

  }

}
manishgarg0 commented 4 years ago

I am also facing the same issue..

bageren commented 4 years ago

I also cannot get any tokens in Chrome. Haven't tried any other browsers. I'm not getting any errors though.

ayyash commented 4 years ago

the only way I got around this is by filling up the firebase service worker file properly, like this

importScripts('https://www.gstatic.com/firebasejs/7.6.0/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/7.6.0/firebase-messaging.js');
  firebase.initializeApp({
   apiKey: “from firebase config”,
   authDomain: “from firebase config”,
   databaseURL: “from firebase config”,
   projectId: “from firebase config”,
   storageBucket: “from firebase config”,
   messagingSenderId: “from firebase config”,
   appId: “from firebase config”,
   measurementId: “from firebase config”
});
  const messaging = firebase.messaging();
jamesdaniels commented 3 years ago

Addressed in recent versions of AngularFire / Firebase.