我已经开始在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