3

I've started playing around with ServiceWorker in Google Chrome v38. I've set #enable-experimental-web-platform-features to True in about:config and setup my localhost to serve requests over https://.

My sw.js file contains simple example:

// The SW will be shutdown when not in use to save memory,
// be aware that any global state is likely to disappear
console.log("SW startup");

self.addEventListener('install', function(event) {
  console.log("SW installed");
});

self.addEventListener('activate', function(event) {
  console.log("SW activated");
});

self.addEventListener('fetch', function(event) {
  console.log("Caught a fetch!");
  event.respondWith(new Response("Hello world!"));
});

and my app.js file:

if ('serviceWorker' in navigator) {
    console.log('registering sw.js');
    navigator.serviceWorker.register('/static/js/sw.js').then(function(reg) {
        console.log('Yey!', reg);
    }, function(err) {
        console.log('Boo!', err);
    });
}

My console output is:

registering sw.js app.js:27
Boo!
DOMException: The Service Worker installation failed. {message: "The Service Worker installation failed.", name: "AbortError", code: 20, INDEX_SIZE_ERR: 1, DOMSTRING_SIZE_ERR: 2…} app.js:31

Any ideas how to troubleshoot this issue?

3 Answers 3

2

Please use Google Chrome 40 or higher (with no chrome://flags fiddling required) when developing with service workers. Chrome 38 may have had some very, very preliminary support for some of the service worker APIs, but both the specification and the maturity of the APIs have changed significantly since Chrome 38. Ditto for Chrome 39.

Ideally, for development purposes, I'd actually recommend using the current Google Chrome Canary (41), since there have been several enhancements to the error messages since the Chrome 40 branch cut, and more accurate/expressive errors help a lot when figuring out what's going wrong.

2
  • I'm using canary (41) with no flag modification and can't make it work locally (http). Commented Jan 5, 2015 at 14:07
  • Service workers normally will only work for pages served via https. There is an exemption that will allow http access when going against localhost, however. If you're testing service workers locally, make sure you're accessing the controlled page via a http://localhost:<port> URL. Commented Jan 5, 2015 at 14:52
1

I've been getting this error for a ServiceWorker with a syntax error. As Chrome doesn't even log the service worker fetch in the Network tab, it took a while to realise that was the cause.

For anyone else getting this error, try in an Incognito tab with an empty sw.js.

0

Also, reporting of syntax errors and Chrome DevTools support in general are still under development for Service Workers. Chrome 42 is in beta as I'm writing this.

Not the answer you're looking for? Browse other questions tagged or ask your own question.