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 }
)
...