I am currently attempting to implement service workers in Chrome on localhost:3000. My application is built using AngularJS 1.5.
The service worker does not seem to be activating properly. It transitions from the installing state to redundant.
if ('serviceWorker' in navigator) {
navigator.serviceWorker
.register('/service-worker.js')
.then(function(registration) {
var serviceWorker;
if (registration.installing) {
serviceWorker = registration.installing;
} else if (registration.waiting) {
serviceWorker = registration.waiting;
} else if (registration.active) {
serviceWorker = registration.active;
}
if (serviceWorker) {
console.log("ServiceWorker phase:", serviceWorker.state);
serviceWorker.addEventListener('statechange', function (e) {
console.log("ServiceWorker phase:", e.target.state);
});
}
})
.catch(function(err) {
console.log('Service Worker Error', err);
});
}
Output from the above script:
ServiceWorker phase: installing
ServiceWorker phase: redundant
You can find the service-worker.js
file at http://localhost:3000/service-worker.js. I have not encountered any error messages. Can anyone help identify what might be causing this issue?