Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

395
Vistas
firebase.messaging.getToken() gives DOMException: Registration failed - push service error

I am making a PWA. I need to save the token to firebase, but I get DOMException: Registration failed - push service error. The return messaging.getToken(); gives the error I mentioned. If I remove the return statement, I get error from firebase, because the token is undefined for obvious reasons.

Here is my code:

const messaging = firebase.messaging();
var perm;
function InitializeFirebaseMessaging(){
  messaging.requestPermission().then(function(){
    
    console.log("Notification permission");
    return messaging.getToken();
  }).then(function(token){
    
    console.log("Token: "+token);
   
    firestore.collection("tokens").doc(auth.currentUser.email).set({
      mail: auth.currentUser.email,
      token: token 
  })//.then(() => {perm=true;});
  
  }).catch(function (reason){
    console.log(reason);
  });
  if(perm){
  ChatRoom();
  }
  return null;
}
messaging.onMessage(function (payload){
  
  console.log("payload:"+payload);
});
messaging.onTokenRefresh(function () {
  messaging.getToken()
      .then(function (newtoken) {
        firestore.collection("tokens").doc(auth.currentUser.email).set({
          mail: auth.currentUser.email,
          token: newtoken 
      })//.then(() => {perm=true;console.log("New Token : "+ newtoken);});
        
          
         
      })
      .catch(function (reason) {
          console.log(reason);
      })
});

So my question is why can't I get my token, why do I get the error mentioned above? I press "accept" when it's asking for permission and I get the error afterwards.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda