我目前正致力于服务工作者在浏览器中处理推送通知.目前我正在进行“SW注册失败错误”.有人可以帮忙解决这个问题吗?检查下面的client1.html和service-worker.js文件:
错误:
SW registration failed with error SecurityError: Failed to register a
ServiceWorker: The URL protocol of the current origin (‘null’) is not
supported.
服务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);
});
client1.html
Client 1if('serviceWorker' in navigator){
// Register service worker
navigator.serviceWorker.register('service-worker.js').then(function(reg){
console.log("SW registration succeeded. Scope is "+reg.scope);
}).catch(function(err){
console.error("SW registration failed with error "+err);
});
}