Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

400
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!