79421692

Date: 2025-02-07 17:31:13
Score: 2
Natty:
Report link

In case someone ends up here, having the same problem with two service workers: For me that was in fact what caused the reload loop and I ended up just combining both service workers. A simple way to do this seems to be to just use importScripts in one service worker to load the other.

If you are using workbox, I can recommend having a look at the importScripts: option that workbox provides, which allows you to include for example the firebase-messaging-sw.js in the workbox service worker. You end up with a single service worker which can be used for both tasks.

I was using VitePWA, so for me it was:

vite.config.ts:

...
VitePWA({
  workbox: {
    importScripts: ['/firebase-messaging-sw.js'],
  }
}
...

and then passing the vite service worker registration to firebase messaging:

...
await firebaseMessaging.getToken(
  messaging,
  { vapidKey, serviceWorkerRegistration: swRegistration }
)
...
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Me too answer (2.5): having the same problem
  • Low reputation (0.5):
Posted by: Dominik Berse