zaru / webpush

webpush, Encryption Utilities for Web Push protocol
MIT License
396 stars 73 forks source link

Webpush::ExpiredSubscription on my device even that I haven't unsubscribed #69

Closed Rubioli closed 5 years ago

Rubioli commented 5 years ago

I have been testing on Chrome Android, Opera & Firefox all latest versions to this date. When I first subscribe, everything goes fine but after 2-4 notifications I get Webpush::ExpiredSubscription, even that I haven't unsubscribed and when I check my browser I still see in browser settings that I have "allowed" notifications.

This is the error I get when I test send: host: fcm.googleapis.com, #<Net::HTTPGone 410 NotRegistered readbody=true> body: <HTML> <HEAD> <TITLE>NotRegistered</TITLE> </HEAD> <BODY BGCOLOR="#FFFFFF" TEXT="#000000"> <H1>NotRegistered</H1> <H2>Error 410</H2> </BODY> </HTML>

I'm not sure why this is still happening and I have tested with several devices with the same result.

Does anyone have any clue about this? I appreciate any help and thanks in advance!

collimarco commented 5 years ago

This is the normal behavior of web push: subscriptions expire after some time and are refreshed by the browser. You need to listen to pushsubscriptionchange event in order to replace the old subscription with the new one.

This is not an issue of this gem and can be closed.

Rubioli commented 5 years ago

Thanks a lot @collimarco

So to understand it correctly, upon delivering the push to the user I can call/listen to pushsubscriptionchange or the user would need to go to the site and it can be updated?

collimarco commented 5 years ago

You should listen for the pushsubscriptionchange event in your service worker. This event can be triggered at any time, even when the user is not on your website.

Rubioli commented 5 years ago

Thanks a lot @collimarco You rock 🥇