我正在我的网站上开发网络推送通知.我遵循Google 的Web推送通知和Mozilla 的服务工作者手册.
我已经在Google Chrome v50 +上进行了测试,一切正常,但我会在调用navigator.serviceWorker.register('./push-service-worker.js')函数时在Firefox 44,45,46,52,最新的Firefox(版本57.0.4 64位)上收到以下错误.
TypeError:位于http:// localhost:9600/push-service-worker.js的 ServiceWorker脚本,范围为http:// localhost:9600 /在安装期间遇到错误.
这是我的代码:
在controller.js中注册ServiceWorker
navigator.serviceWorker.register('push-service-worker.js')
.then((registration) => {
return registration.pushManager.getSubscription()
.then((subscription) => {
if (subscription) {
return subscription;
}
var subscribeOptions = {
userVisibleOnly: true,
applicationServerKey: buildApplicationServerKey(),
};
return registration.pushManager.subscribe(subscribeOptions);
});
})
.then((subscription) => {
sendSubscriptionToServer(subscription);
})
.catch((err) => {
console.log('Unable to subscribe to push: ', err);
});
Run Code Online (Sandbox Code Playgroud)
推送服务worker.js
'use strict';
self.addEventListener('push', (event) => {
var payload = event.data.json();
var …Run Code Online (Sandbox Code Playgroud)