service worker - navigator.serviceWorker is never ready -
i registered service worker successfully, code
navigator.serviceworker.ready.then(function(serviceworkerregistration) { // have push message subscription? ....
hangs -- function never called. why?
the problem service-worker.js file stored in assets
sub-directory.
don't that: store service-worker.js in root of app
(or higher). way app can access service-worker.
see html5rocks article --
one subtlety register method location of service worker file. you'll notice in case service worker file @ root of domain. means service worker's scope entire origin. in other words, service worker receive fetch events on domain. if register service worker file @ /example/sw.js, service worker see fetch events pages url starts /example/ (i.e. /example/page1/, /example/page2/).
added
a new problem serviceworker never ready if page hard-reloaded. subsequent soft page reloads work fine. google's own sample code fails. see chrome bug report.
the bug fix included chrome 44.
Comments
Post a Comment