Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Service worker throwing an net::ERR_FILE_EXISTS error?

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);
        });
}
like image 974
sidthesloth Avatar asked Oct 25 '15 10:10

sidthesloth


1 Answers

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".

like image 183
john holt ripley Avatar answered Nov 03 '22 06:11

john holt ripley