javascript - CacheStorage.open() 在 Chrome 中返回未定义

标签 javascript google-chrome browser-cache

我的爱好网站上有一个 service worker,它有一个 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());
        });
    }));
}

在 Firefox 中这工作得很好,但 Chrome 65 从 caches.open("core-waiting") 返回 undefined,所以当我尝试时它抛出错误在 core 上调用 putAccording to the docs ,这应该是不可能的。知道这里发生了什么吗?

最佳答案

原来Visual Studio打开的Google Chrome窗口无法使用缓存API,只是默默返回undefined。如果您手动打开 Chrome 窗口,它就可以正常工作。

真的应该有一个关于这个的控制台警告,这样开发人员就不会浪费时间为此挠头......

关于javascript - CacheStorage.open() 在 Chrome 中返回未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49774541/

相关文章:

c# - 推送通知 Chrome Mobile Ver 42+

javascript - Chrome jQuery 表单插件跨域安全漏洞?

javascript - webpack block 和 vue.js 组件的浏览器缓存问题

ssl - 浏览器多久会自动重置 SSL 缓存?

javascript - 下拉列表的第一项未定义

javascript - 从谷歌浏览器扩展调用页面功能

javascript - 计算动态html表格的总计和小计

php - PHP 是否可以设置为从不缓存响应,并始终向页面发送新内容?

javascript - 如何在声明后获取 jQuery 元素

javascript - Chai 测试对象数组到 "contain something like"对象子匹配