47
service-worker.js:1 GET http://localhost:8080/service-worker.js net::ERR_FILE_EXISTS

This is the error I get every time I refresh after registering a service worker. I've made sure that the service-worker.js file exists in the root directory. Also the service worker is registered and working fine. But I still keep getting this error. Also I'm working on localhost.

This is my service-worker.js file:

console.log("SW startup");

var CACHE_NAME = "my_cache";
var urlsToCache = [
  './',
  './css/style.css',
  './js/script.js'
];

self.addEventListener('install', function(event) {
  // Perform install steps
  event.waitUntil(
    caches.open(CACHE_NAME)
      .then(function(cache) {
        console.log('Opened cache');
        return cache.addAll(urlsToCache);
      })
  );
});

self.addEventListener('fetch', function(event) {
  event.respondWith(
    caches.open(CACHE_NAME).then(function(cache) {
      return cache.match(event.request).then(function (response) {
        return response || fetch(event.request.clone()).then(function(response) {
          console.dir(response);
          console.log('hi');
          cache.put(event.request.clone(), response.clone());
          return response;
        });
      });
    })
  );
});

script.js file:

if (navigator.serviceWorker) {
    console.log("ServiceWorkers are supported");


    navigator.serviceWorker.register('service-worker.js')
        .then(function(reg) {
            console.log("ServiceWorker registered ◕‿◕");
            console.dir(reg);
        })
        .catch(function(error) {
            console.log("Failed to register ServiceWorker ಠ_ಠ");
            console.dir(error);
        });
}
0

1 Answer 1

32

I'm seeing the same issue. It can safely be ignored.

This bug tracks removing the noise from Chrome: https://code.google.com/p/chromium/issues/detail?id=541797

It should be live starting with Chrome 50.

From thread:

Improve error code for service worker bailing due to no update found

ServiceWorkerWriteToCacheJob is the URLRequestJob responsible for fetching and writing the updated script. It fails with network error when it wants to abort the update because the new script is the same as the old one.

Currently that results in ERR_FAILED errors appearing in the DevTools console and netlog, which is confusing and hard to debug because that error also occurs for actual network errors. This patch changes the error to FILE_EXISTS, so it's more clear why the job "failed".

3
  • are you saying i let this error come in production code of my site ??///.....also why does this same error not come up in other websites consoles (other websites that have implemented service worker ???) Dec 22, 2015 at 10:00
  • @amansatija Facebook shows the error after a few seconds if you keep the console open. Jan 4, 2016 at 16:07
  • ya i noticed it , now a days it comes on every site that have implemented service worker ...>!!! even pinterest Jan 4, 2016 at 16:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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