我正在尝试注册服务工作者,但出现以下错误:
注册ServiceWorker失败:当前的URL协议
不支持原点('null')
我在 localhost 下使用 Node js,我有我的索引.html and service-worker.js在同一个文件夹中
索引.html
<!doctype html>
<html>
<head>
<title>TryService</title>
</head>
<body>
PROVA SITO CON SERVICE WORKER
<script>
if('serviceWorker' in navigator){
// Register service worker
navigator.serviceWorker.register('service-worker.js').then(function(reg){
console.log("Registration OK!. Scope is "+reg.scope);
}).catch(function(err){
console.error("Registration FAILED! "+err);
});
}
</script>
</body>
</html>
service-worker.js
console.log('Started', self);
self.addEventListener('install', function(event) {
self.skipWaiting();
console.log('Installed', event);
});
self.addEventListener('activate', function(event) {
console.log('Activated', event);
});
self.addEventListener('push', function(event) {
console.log('Push message received', event);
});
我该如何修复它?
先感谢您!
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)