I have an Ionic 5 PWA using Angular 8. I had done Push Notifications using swPush which was working as expected till March. But, from last month, due to some other changes, this stopped working. I am not able to isolate the issue.
swPush.isEnabled()
is returning false, even though service worker is registered. Nothing has changed in the code with respect to swPush and its implementations. I tried this unanswered link and did not help as well
When I use PUSH NOTIFICATION API (using PushManager), there are NO errors and everything is working and I am getting subscription object back. Is this a problem with swPush implementation, or my mistake?
notification-service.ts
this.swPush.requestSubscription({
serverPublicKey: this.VAPIDPublicKey
})
.then((sub: PushSubscription) => {
const keys: SubscriptionObjectKeys = {
auth: sub.toJSON().keys.auth,
p256dh: sub.toJSON().keys.p256dh
};
const subscriptionObject: SubscriptionObject = {
endpoint: sub.endpoint,
expirationTime: 0,
keys: keys
};
resolve(subscriptionObject);
})
.catch(err => {
console.error('Could not subscribe to notifications', err);
reject(err);
});
Error in Chrome
Error: Service workers are disabled or not supported by this browser
at e.requestSubscription (service-worker.js:391)
at notification.service.ts:123
at new D (zone-evergreen.js:960)
at t.<anonymous> (notification.service.ts:103)
at Generator.next (<anonymous>)
at tslib.es6.js:73
at new D (zone-evergreen.js:960)
at o (tslib.es6.js:69)
at t.subscribeToSWPush (common-es2015.ffedc7b115b497dcd514.js:1)
at t.<anonymous> (notification.service.ts:61)
I have checked this in macOS and Windows 10 as well, with HTTP Server and SSL. Both shows same problem.
I created a new Ionic app and implemented the same code, which is working fine there. I am not able to isolate the issue.
Any suggestion would be really helpful.