Service Workerを作成する方法と、Chromeで意図したとおりに動作している間に、Firefox v56で動作していない不明な理由があります。ここではどこでもhttps://mdn.github.io/sw-test/FirefoxでService Workerを起動するには?
作業しなければならないデモは、このデモサービスワーカーコードである
self.addEventListener('install', function(event) {
event.waitUntil(
caches.open('v1').then(function(cache) {
return cache.addAll([
'/sw-test/',
'/sw-test/index.html',
'/sw-test/style.css',
'/sw-test/app.js',
'/sw-test/image-list.js',
'/sw-test/star-wars-logo.jpg',
'/sw-test/gallery/bountyHunters.jpg',
'/sw-test/gallery/myLittleVader.jpg',
'/sw-test/gallery/snowTroopers.jpg'
]);
})
);
});
self.addEventListener('fetch', function(event) {
event.respondWith(caches.match(event.request).then(function(response) {
// caches.match() always resolves
// but in case of success response will have value
if (response !== undefined) {
return response;
} else {
return fetch(event.request).then(function (response) {
// response may be used only once
// we need to save clone to put one copy in cache
// and serve second one
let responseClone = response.clone();
caches.open('v1').then(function (cache) {
cache.put(event.request, responseClone);
});
return response;
}).catch(function() {
return caches.match('/sw-test/gallery/myLittleVader.jpg');
});
}
}));
});
私はデベロッパーコンソールを開くと、私はこのエラーを取得:同じ時間で "Registration failed with TypeError: ServiceWorker script at https://mdn.github.io/sw-test/sw.js for scope https://mdn.github.io/sw-test/ encountered an error during installation."
、これを同じコードがChromeでエラーなく動作します。
about:config
設定dom.serviceWorkers.enabled
はtrue
に設定されています。 私はすべてのプラグインも無効にしていますが、まだ動作していません。
何が問題なのですか?