简体   繁体   English

在 Nuxtjs 中注册 Service Worker

[英]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.

相关问题 FirebaseError:我们无法注册默认服务工作者 - FirebaseError : We are unable to register the default service worker 错误:消息:我们无法注册默认服务工作者 - Error: Messaging: We are unable to register the default service worker Angular + Firebase:无法注册默认服务工作者。 scope注册ServiceWorker失败 - Angular + Firebase: unable to register default service worker. Failed to register a ServiceWorker for scope 收到错误“FirebaseError:消息:我们无法注册默认服务工作者。” 使用 Sveltekit 设置消息传递 - Getting error "FirebaseError: Messaging: We are unable to register the default service worker." setting up messaging with Sveltekit 将依赖项导入服务工作者 - Import a dependency to a service worker 如何解决服务人员导航“此服务人员不是客户端的活动服务人员”错误? - How to solve service worker navigate "This service worker is not the client's active service worker" error? 在 cloudflare worker 中批量调用外部服务 - Batching external call to external service in cloudflare worker Google Chrome 中的 Service-Worker 警告 - Service-Worker Warning in Google Chrome 使用 firebase 托管和功能的 Service Worker 注册失败 - Service Worker registration fails with firebase hosting and functions firebase 通知事件在 service worker 中不起作用(notifcationclose、notificationclick) - firebase notification events not working in service worker (notifcationclose, notificationclick)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM