I am trying to glue together a Nuxt 3 PWA with vite-plugin-pwa
, more specifically @vite-pwa/nuxt
. I installed the module and set up basic configuration (I basically followed this video)
What I want
The first feature I would like to implement is sending Push Notifications to users at fixed time. They should receive the Push Notifications even if they are not in the app. That's why I added the PWA module.
What I do not understand
I don't know how to add my custom service worker. If I understand it correctly, I could write a service worker, that just sends Push Notifications with the Notification API to my app. No need for services like OneSignal (right?).
As I understand the documentation Vite PWA uses google's workbox under the hood and per default it generates a service worker. If you set injectRegister: 'script'
it should inject a service worker registration in the head of my app (like described here).
Now when I search the source code via the developer tools I cannot find any serviceWorker script. Strangely enough, when I go to the application tab in the dev tools, I can see that a service worker dev-sw.js
is registered. How did this get added?
β
I think I have to set a mode in the configuration to tell workbox not to generate the service worker registration for me. This mode should be called injectManifest, as described here and here. But again, how do I add this to my code?
As suggested in the documentation I also had a look at the elk repo. But unfortunately they take a different approach and currently do not use vite-pwa/nuxt.
How can I add my custom service worker to send push notifications?
Does anybody have experience with PWAs in Nuxt 3 and specifically working with service workers and sending Push Notifications?