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.