我已经和这个问题斗争了几个月了,但还是弄不明白。我已经使用了一段时间的服务工作者,现在没有问题,但最近我会加载我的网站的主页,然后做一个简单的刷新,我将被服务于离线页面(如果我从缓存中删除离线页面,它会刷新到连接错误屏幕)。这只发生在主页上,并且一定与Fetch API有关(见下文)。fetch错误只是"Failed to fetch“,不包含任何额外的错误信息。
我的清单设置了适当的/作用域,并且sw.js文件位于根目录中。就像我提到的,在Chrome 66 (和之前)没有做任何改变的情况下,它运行得很好,但在更新到67和68的稳定版本后出现了问题。在所有其他支持service worker的浏览器(包括Chrome Canary)中,这不是问题。
涉及的代码太多了,我不知道如何将其简明扼要地归结为这样一篇文章,但这是我的测试用例(我在匿名模式和常规模式下都运行过)。此代码位于/nebula/子目录(此网站的根目录)中的服务工作者文件sw.js中。我一直将我的笔记保存在Github中,因此可以在这里获得更详细的解释和其他屏幕截图:https://github.com/chrisblakley/Nebula/issues/1709 (Particularly this post here)
console.log('(A) about to fetch via sw');
fetch('https://gearside.com/nebula/get-started/checklists/').then(function(response) {
console.log('(A) we got it!', response);
}).then(function(returnedValue) {
console.log('(A) returning the value!', returnedValue);
}).catch(function(err) {
console.log('(A) fetch error:', err);
});
console.log('(B) about to fetch via sw');
fetch('https://gearside.com/nebula/').then(function(response) {
console.log('(B) we got it!', response);
}).then(function(returnedValue) {
console.log('(B) returning the value!', returnedValue);
}).catch(function(err) {
console.log('(B) fetch error:', err);
});"(A)“控制台日志获取一个子页面,并且总是成功,但是"(B)”日志获取主页总是失败。

这是我的网络选项卡,用来显示其他软件抓取工作正常:

作为参考,我的manifest.json (我删减了几个简短的图标):
{
"name": "Nebula: Advanced Starter WordPress Theme for Developers",
"short_name": "Nebula",
"description": "Advanced Starter WordPress Theme for Developers",
"theme_color": "#0098d7",
"background_color": "#f6f6f6",
"gcm_sender_id": "",
"scope": "/",
"start_url": "https://gearside.com/nebula/?utm_source=homescreen",
"display": "standalone",
"orientation": "portrait",
"icons": [{
"src": "https://gearside.com/nebula/wp-content/themes/Nebula-master/assets/img/meta/android-chrome-512x512.png",
"sizes": "512x512",
"type": "image/png"
}]
}当安装软件时,它会缓存几个文件(这涉及到一些自动化,但从未出现过问题):
var CACHE_NAME = 'nebula-nebula-child-27905'; //Wednesday, August 8, 2018 11:59:21 PM
var OFFLINE_URL = 'https://gearside.com/nebula/offline/';
var OFFLINE_IMG = 'https://gearside.com/nebula/wp-content/themes/Nebula-master/assets/img/offline.svg';
var META_ICON = 'https://gearside.com/nebula/wp-content/themes/Nebula-master/assets/img/meta/android-chrome-512x512.png';
var MANIFEST = 'https://gearside.com/nebula/wp-content/themes/Nebula-master/inc/manifest.json';
var HOME_URL = 'https://gearside.com/nebula/';
var START_URL = 'https://gearside.com/nebula/?utm_source=homescreen';在我的站点的JavaScript文件中,它会根据需要将其他页面发送到缓存。
以前有没有其他人在他们的服务工作者或Fetch API中遇到过这种情况?如果需要的话,我很乐意分享更多的信息。我的一线希望是,这将神奇地修复自己与Chrome 69或70,因为它是在金丝雀工作……但我更喜欢弄清楚万一没有发生的情况会发生什么。
发布于 2018-08-16 20:38:02
在Chrome68中尝试来宾配置文件后,两个抓取都起作用了。在使用扩展进行故障排除后,结果表明这是由uBlock源引起的-尽管域名被列入白名单。当该扩展被完全禁用时,两个fetches都会再次工作。
https://stackoverflow.com/questions/51833056
复制相似问题