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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With