我的业余爱好站点上有一位服务人员,他的install事件处理程序看起来如下(在TypeScript中):
/**
* When the service worker is being intalled, download the required assets into a temporary cache
* @param e The intall event
*/
function installHander(e: ExtendableEvent): void {
"use strict";
// Put updated resources in a new cache, so that currently running pages
// get the current versions.
e.waitUntil(caches.delete("core-waiting").then(() => {
return caches.open("core-waiting").then((core) => {
const resourceUrls = [
"/",
"/loading/",
"/offline/",
"/css/site.css",
"/js/site.js"
];
return Promise.all(resourceUrls.map((key) => {
// Make sure to download fresh versions of the files!
return fetch(key, { cache: "no-cache" })
.then((response) => core.put(key, response));
}))
// Don't wait for the client to refresh the page (as this site is designed not to refresh)
.then(() => (self as ServiceWorkerGlobalScope).skipWaiting());
});
}));
}在火狐中,这很好,但是Chrome 65从caches.open("core-waiting")返回caches.open("core-waiting"),所以当我试图在core上调用put时,它会抛出一个错误。根据医生的说法,这应该是不可能的。知道这是怎么回事吗?
发布于 2019-02-01 21:38:28
事实证明,Visual打开的Google窗口不能使用缓存API,只能默默地返回未定义的内容。如果你手动打开Chrome窗口,它就能正常工作。
确实应该有一个控制台警告这一点,这样开发者就不会浪费时间在这件事上绞尽脑汁.
发布于 2020-02-20 23:54:34
这实际上是因为这个Chromium:https://bugs.chromium.org/p/chromium/issues/detail?id=1054541
基本上,Visual设置的用户数据dir开关“太长”,破坏了Chrome中的服务工作者缓存API。
您应该能够在中使用"Browse With.“来解决这个问题。选项设置Chrome启动没有自定义-用户-数据-dir(或设置自己的)。
https://stackoverflow.com/questions/49774541
复制相似问题