I have learned to implement push notifications for a Web Application using chrome https://developers.google.com/web/updates/2015/03/push-notifications-on-the-open-web?hl=en and successfully ran the sample code mentioned in the blog.
Unfortunately, I couldn't replicate the success with Django. It never goes into the ready method of the service worker,(navigator.serviceWorker.ready.then) ie, the service worker is never ready.
As per http://www.html5rocks.com/en/tutorials/service-worker/introduction/
One subtlety with the register method is the location of the service
worker file. You'll notice in this case that the service worker file
is at the root of the domain. This means that the service worker's
scope will be the entire origin. In other words, this service worker
will receive fetch events for everything on this domain. If we
register the service worker file at /example/sw.js, then the service
worker would only see fetch events for pages whose URL starts with
/example/ (i.e. /example/page1/, /example/page2/).
In Django, how to put a JS a file under root of the application? Currently,scope of the service worker is: http://127.0.0.1:8000/static/ (When I use chrome://serviceworker-internals/)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…