2

I'm trying to register the Service worker and getting an error:

DOMException: Operation failed by network issue

The page is hosted using github pages: https://boopathi.in/sw-demo-iss. and the source code is here https://github.com/boopathi/sw-demo-iss

I'm trying to understand what that means and how to resolve errors.

Boopathi Rajaa
  • 4,659
  • 2
  • 31
  • 53

2 Answers2

4

Chrome seems to be trying to load/register https://boopathi.in/sw-demo-iss/sw.bundle.js as the service worker, but that 404s. So you probably need to fiddle with paths a bit. Maybe register('sw.bundle.js') will work?

mjs
  • 63,493
  • 27
  • 91
  • 122
  • +1. Erroneous dots and slashes in the registration URL can have unintended consequences. Look at them carefully when you have this issue! – owencm Feb 14 '15 at 08:11
2
if('serviceWorker' in navigator) {
    navigator.serviceWorker.register('sw.bundle.js', {
        scope: 'isstracker'
    }).then(function(reg) {
        console.log("Service worker registered")
    }).catch(function(err) {
        console.log(err);
    });
}

You scoped the serviceworker to isstracker, that means that your serviceworker will work only for everything after the isstracker/ path, but the demo is hosted on the sw-demo-iss/ path. This is most probably the cause of the SecurityError you're getting:

"The Service Worker security policy prevented an action."
Sandro Paganotti
  • 2,295
  • 16
  • 12