我已經開始在Google Chrome v38中使用ServiceWorker
。我已將#enable-experimental-web-platform-features
設置爲True
,並將其設置爲about:config
,並將我的本地主機設置爲通過https://
服務請求。註冊ServiceWorker返回AbortError代碼:20
我sw.js
文件包含簡單的例子:
// The SW will be shutdown when not in use to save memory,
// be aware that any global state is likely to disappear
console.log("SW startup");
self.addEventListener('install', function(event) {
console.log("SW installed");
});
self.addEventListener('activate', function(event) {
console.log("SW activated");
});
self.addEventListener('fetch', function(event) {
console.log("Caught a fetch!");
event.respondWith(new Response("Hello world!"));
});
和我app.js
文件:
if ('serviceWorker' in navigator) {
console.log('registering sw.js');
navigator.serviceWorker.register('/static/js/sw.js').then(function(reg) {
console.log('Yey!', reg);
}, function(err) {
console.log('Boo!', err);
});
}
我的控制檯輸出爲:
registering sw.js app.js:27
Boo!
DOMException: The Service Worker installation failed. {message: "The Service Worker installation failed.", name: "AbortError", code: 20, INDEX_SIZE_ERR: 1, DOMSTRING_SIZE_ERR: 2…} app.js:31
任何想法如何解決這個問題呢?
我正在使用金絲雀(41)沒有修改標誌,並且無法使其在本地工作(http)。 – Aleksandrenko 2015-01-05 14:07:17
服務人員通常只會在通過「https」服務的頁面上工作。但是,有一種豁免會允許在與'localhost'相對時使用'http'訪問。如果您在本地測試服務人員,請確保您通過「http:// localhost:」URL訪問受控頁面。 –
2015-01-05 14:52:29
它在本地工作,我打破了實施。 :) – Aleksandrenko 2015-01-06 09:04:52