Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The provided web push applicationServerKey is not valid

I am trying to subscribe to web push via the function below.

function postSubscriptionBo() {
  return navigator.serviceWorker.register('/service-worker.js')
  .then(function(registration) {
    const subscribeOptions = {
      userVisibleOnly: true,
      applicationServerKey: APPLICATION_SERVER_KEY
    };

    return registration.pushManager.subscribe(subscribeOptions);
  })
  .then(function(pushSubscription) {
    console.log('Received PushSubscription: ', JSON.stringify(pushSubscription));
    return pushSubscription;
  });
}

These are the current steps:
1. Get the application server key from Firebase console > cloud messaging tab > server key
2. Encoded application server key with window.btoa(server key)
3. Removed tailing = from the server key
4. Browser throws exception: The provided web push applicationServerKey is not valid.

Suggestions on what I am doing wrong here? Thanks.

like image 930
antrunner Avatar asked Jan 30 '26 10:01

antrunner


1 Answers

In the cloud messaging tab instead of using the server key, after generating a Web Push certificates public key (at the bottom of the same cloud messaging tab) and adding it instead of the server key, it worked.

like image 120
antrunner Avatar answered Feb 03 '26 10:02

antrunner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!