I'm working with Firebase Cloud Messaging and it requires me to have the default Firebase Service Worker as "firebase-messaging-sw.js" inside of my project. How can I retrieve the existing service worker that Firebase registers with their script I'm using, so I don't have to registered it manually?
One of the lines inside inside the scripts I'm importing from firebase registers the service worker.
html file
<script src="https://www.gstatic.com/firebasejs/7.6.1/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.6.1/firebase-messaging.js"></script>
my js file:
//Register the service worker
navigator.serviceWorker
.register('../../firebase-messaging-sw.js')
.then(swReg => {
console.log('Service Worker is registered', swReg);
swRegistration = swReg;
})
.catch(error => {
console.error('Service Worker Error', error);
});
As you can see I'm re-registering the same service worker, but I shouldn't do that. Yes, I can create an other service worker but for what I know I shouldn't do that.
Here you can see the to registered service workers.
As you can see the first one is the one firebase registered, the second one is the one I do "manually"