Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

396
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda