javascript - Deleting Service worker cache crashes
问题描述
I have added the following (sample) code to my app (Angular app, is true for any JS app) to delete the serviceworker cache:
if ('serviceWorker' in navigator) {
if ('caches' in window) {
caches.keys().then((keyList) => {
return Promise.all(keyList.map(function (key) {
return caches.delete(key);
}));
});
}
}
But I frequently receive crash reports with the following error for some users using Chrome 72 and above for Windows:
TypeError · undefined is not a function
for function
caches.keys
Anyone has any idea why this could be happening.
解决方案
您可以从cache.open
函数中获取缓存对象。
示例用法:
caches.open(name).then(function(cache) {
cache.keys().then(function(keys) {
//Do something with keys
});
})
推荐阅读
- javascript - 仅当在多选中选择了特定选项时才显示输入字段
- android - 在 Bluestack Android Emulator 上进行 Android 调试
- c# - Generic Cast,将 int 转换为 double 是不可能的
- vb.net - 插入 & [declaredTABLENAME] & [SQLQUERY]
- c# - System.Diagnostics.Process 在发布 MVC 应用程序后不起作用
- python - XGBoost - XGBClassifier predict_proba(python)的奇怪结果
- azure-service-fabric - 运行测试时 Azure Service Fabric 在本地群集中终止
- spring - Spring boot:上传几个 MultipartFile 和几个附加数据
- python - 在 python 3 中扩展一个类,以便可以迭代 ls_1 和 ls_2 的索引 i 处的元素对。索引 i 从 0 开始
- rcpp - RcppEigen 和包大小