'InvalidStateError'
で約束を拒否される原因は何ですか? Firefoxバージョン52でPromiseがここで「InvalidStateError」で拒否される原因は何ですか?
const SERVICE_WORKER_VERSION = "3.0.0"; // is updated in the build when things change
const CACHE_VERSION = SERVICE_WORKER_VERSION;
const fillServiceWorkerCache = function() {
/* save in cache some static ressources
this happens before activation */
return caches.open(CACHE_VERSION).then(function(cache) {
return cache.addAll(ressourcesToSaveInCache);
});
};
self.addEventListener("install", function (event) {
/*event.waitUntil takes a promise that should resolves successfully*/
event.waitUntil(fillServiceWorkerCache().then(function() {
return self.skipWaiting();
}));
});
次のエラーが発生します。Service worker event waitUntil() was passed a promise that rejected with 'InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable'.
サービスワーカーが殺され、その後削除されます。 Chromeでうまく動作します。 ressourcesToSaveInCache
は、相対URLの配列です。
編集
event.waitUntil(
fillServiceWorkerCache()
.then(skipWaiting)
.catch(skipWaiting)
);
とサービスワーカーレジスタにそれを変えます!しかし、fillServiceWorkerCache
は拒否されました。これは大きな問題です(オフラインキャッシュなし)。今質問はなぜfillServiceWorkerCache
が拒否するのですか、そして何を伝えようとしているエラーメッセージですか? Hosarの答えに触発
編集:
const fillServiceWorkerCache2 = function() {
return caches.open(CACHE_VERSION).then(function (cache) {
return Promise.all(
ressourcesToSaveInCache.map(function (url) {
return cache.add(url).catch(function (reason) {
return console.log(url + "failed: " + String(reason));
})
})
);
});
};
このバージョンでは、waitUntil()
が実際にそれを待つ作り、リターンチェーンの約束を伝播します。それはキャッシュされず、キャッシュに追加されなかった個々のリソースについても拒否しません。
編集2:ressourcesToSaveInCacheに無効な相対URLを固定した後、エラーが消えていた