a7ul / web-push-demo

A blog demo to showcase how push notification works in web
https://blog.atulr.com/web-notifications
98 stars 56 forks source link

Error DOMException #8

Open b1tw0rker opened 3 years ago

b1tw0rker commented 3 years ago

When Clicking on "Ask Permission". I got these error:

Error DOMException: Failed to execute 'subscribe' on 'PushManager': Subscription failed - no active Service Worker at http://localhost:3000/service.js:31:66

davidzwa commented 2 years ago

I was able to fix the situation by listening to the "activate" event instead. The installing event is not good enough and causes the push manager not to be ready for subscription.

Find out why here https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API/Using_Service_Workers