服务工作者抛出net :: ERR_FILE_EXISTS错误? [英] Service worker throwing an net::ERR_FILE_EXISTS error?

查看:181
本文介绍了服务工作者抛出net :: ERR_FILE_EXISTS错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

这是我在注册服务工作人员后每次刷新时所得到的错误。我确定service-worker.js文件存在于根目录中。此外,服务人员已注册并正常工作。但我仍然不断收到这个错误。



这是我的service-worker.js文件:

  console.log(SW启动); 

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

self.addEventListener('install',function(event){
//执行安装步骤
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){
返回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档案:



<$ p $如果(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(注册ServiceWorker失败) ;
console.dir(error);
});
}


解决方案

问题。它可以安全地被忽略。



这个错误跟踪消除Chrome中的噪音: https://code.google.com/p/chromium/issues/detail?id=541797



来自线程:


由于没有更新发现,改善了服务工作者保管的错误代码。

ServiceWorkerWriteToCacheJob是负责
读取和写入更新脚本的URLRequestJob。当它想要中止更新时,它会因网络错误
而失败,因为新脚本与旧脚本是相同的



目前,结果在DevTools
控制台和netlog中出现的ERR_FAILED错误,这是令人困惑和难以调试的,因为
错误也出现在实际的网络错误中。此修补程序将
错误更改为FILE_EXISTS,所以更清楚为什么作业失败。



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);
        });
}

解决方案

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

这篇关于服务工作者抛出net :: ERR_FILE_EXISTS错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆