w3c / push-api

Push API
https://w3c.github.io/push-api/
Other
145 stars 40 forks source link

A subscription with a different application server key already exists. #296

Closed Caaalabash closed 6 years ago

Caaalabash commented 6 years ago

I meet an error that when I use pushManager.subscribe() on my phone (Firefox 60.0.1)

A subscription with a different application server key already exists.

It works on my laptop(Firefox 60.0.1) ,even my roommate's computer(Firefox 60.0.1),heres my code

  if('PushManager' in window){
    navigator.serviceWorker.ready.then((swReg) => {
      console.log('PushManage registration success')
      swReg.pushManager.getSubscription().then(function(subscription){
        if(subscription){
          console.log(subscription)
        }else{
          console.log('start subscribe')
          swReg.pushManager.subscribe({
            userVisibleOnly:true,
            applicationServerKey:urlBase64ToUint8Array('xxxxx')
          }).then((res)=>{
            api.subscription({data:JSON.stringify(res)})
          }).catch(e=>{
            console.log('error:'+e)
          }).finally(()=>{
            console.log('gg')
          })
        }
      })
    })
  }

I have tried change my applicationServerKey ,didn't work.

ask for help

martinthomson commented 6 years ago

This isn't the right place to look for help using the API, or Firefox.

mondjunge commented 2 years ago

One need to revoke the (Browser-)Permission to send push-notifications to end the subscription with the old ApplicationServerKey, before subscribing with a new one. Or just unsubscribe before changing the ApplicationServerKey. Do not change the ApplicationServerKey in Production or this will happen to your subscribers.