首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CacheStorage.open()返回未定义的Chrome

CacheStorage.open()返回未定义的Chrome
EN

Stack Overflow用户
提问于 2018-04-11 11:58:48
回答 2查看 1.1K关注 0票数 1

我的业余爱好站点上有一位服务人员,他的install事件处理程序看起来如下(在TypeScript中):

代码语言:javascript
复制
/**
 * 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时,它会抛出一个错误。根据医生的说法,这应该是不可能的。知道这是怎么回事吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-02-01 21:38:28

事实证明,Visual打开的Google窗口不能使用缓存API,只能默默地返回未定义的内容。如果你手动打开Chrome窗口,它就能正常工作。

确实应该有一个控制台警告这一点,这样开发者就不会浪费时间在这件事上绞尽脑汁.

票数 3
EN

Stack Overflow用户

发布于 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(或设置自己的)。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49774541

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档