pusher / push-notifications-web

Beams Browser notifications
MIT License
39 stars 19 forks source link

How to properly config pusher notifications web with Vercel hosted PWA application? #148

Closed fescherer closed 7 months ago

fescherer commented 7 months ago

Hello. I am recently creating a PWA application to send notifications with pusher. For some reason in the localhost the notifications works, but when I deployed to vercel and teste on browser and PWA installed version, none of them works. I searched a lot and could not find a proper tutorial or some docs that could help me.

The error is this from the image below: image

As it says could not find the function, because of this, I think the script from pusher is not been loaded. This is my next config: image

Also, what is the minimum code for my service worker?

benw-pusher commented 7 months ago

You can find instructions on the service worker at https://pusher.com/docs/beams/getting-started/web/sdk-integration/#create-a-service-worker.

The error message looks like the code has been minified, which makes following the stack trace impossible. Are you able to run a build without this and share the error?

What device/browser are you using for this test?

fescherer commented 7 months ago

You can find instructions on the service worker at https://pusher.com/docs/beams/getting-started/web/sdk-integration/#create-a-service-worker.

The error message looks like the code has been minified, which makes following the stack trace impossible. Are you able to run a build without this and share the error?

What device/browser are you using for this test?

Hello, sorry for the late reply, I was testing some stuff and probably my service worker was wrong, but even now that I think I made everthing fine, it still doesn't work :/

About the error, yes, probably is because minification. I never made a pwa app so I just followed the instructions using https://www.npmjs.com/package/next-pwa, but essentially I made a folder worker with index,js and inside importScripts('https://js.pusher.com/beams/service-worker.js') just like https://github.com/shadowwalker/next-pwa/tree/master/examples/web-push but using the worker for pusher.

Now, my nextjs.config is this: image

And the when running build, it creates three files sw,js and the two workbox. image

So the pusher script is called sw.js insted service-worker.js as your doc link says... Could be it the issue I am having?

Edit

I could make the build with name service-worker.js by adding this to next config: image But still does not work :/

fescherer commented 7 months ago

I found that next-pwa does not support app router from Next 13. And because of this, the service worker is acting weird. I am gonna close this issue because it is not related to Pusher