[英]Register Service Worker in Nuxtjs
I am trying to register service worker in my nuxt application.我正在尝试在我的 nuxt 应用程序中注册服务人员。 the problem i am facing is registering the firebase-messaging-sw.js file
我面临的问题是注册 firebase-messaging-sw.js 文件
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('./firebase-messaging-sw.js')
.then(function(registration) {
console.log('Registration successful, scope is:', registration.scope);
}).catch(function(err) {
console.log('Service worker registration failed, error:', err);
});
}
Here is the error i received in the console这是我在控制台收到的错误
Messaging: We are unable to register the default service worker. Failed to register a ServiceWorker: A bad HTTP response code (404) was received when fetching the script
You don't need to register service worker, it's automatically registered.您不需要注册 Service Worker,它会自动注册。
Also, I didn't found a way to use v9 modular code inside service worker.另外,我没有找到在 service worker 中使用 v9 模块化代码的方法。
Only v8 code works:只有 v8 代码有效:
importScripts('https://www.gstatic.com/firebasejs/8.10.1/firebase-app.js')
importScripts('https://www.gstatic.com/firebasejs/8.10.1/firebase-messaging.js')
It may have some bugs with this service worker, after each update it stops to work.这个服务工作者可能有一些错误,每次更新后它都会停止工作。 Looking for another solution... I will consider replace firebase notification with something different.
寻找另一种解决方案...我会考虑用不同的东西替换 firebase 通知。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.