binwiederhier / ntfy

Send push notifications to your phone or desktop using PUT/POST
https://ntfy.sh
Apache License 2.0
18.54k stars 729 forks source link

iOS PWA problems #1203

Open gw8484 opened 1 month ago

gw8484 commented 1 month ago

:lady_beetle: Describe the bug

When opening iOS PWA after getting push notification it often does not:

  1. Update the notification display with the new notification messages.
  2. Update the badge count display on the PWA home screen icon.

The iOS PWA should update immediately when opened after new push notification is received and it should reset the badge count on the iOS PWA home screen icon.

BTW, the same web app works as expected in a Chrome browser on a Linux desktop.

:computer: Components impacted

iOS 17.6.1 ntfy v2.11.0 self hosted Docker instance on Ubuntu 22.04

:bulb: Screenshots and/or logs

Here is a snippet of the server log when the PWA opens but DOES NOT update where the subscription topic (/appm1) does not appear to be requested (Note, the public IP addresses have been changed):

2024/10/21 23:42:10 DEBUG HTTP request started (http_method=GET, http_path=/st_1DxBLrCgXJYXZ/ws?auth=QmVhcmVyIHRrX245NnE1OHk2anVieWx1MHFzdWZzaHlrcnoyNmR1, tag=http, user_id=u_11sCmqbbhZ, user_name=user1, visitor_auth_limiter_limit=0.016666666666666666, visitor_auth_limiter_tokens=30, visitor_id=ip:77.77.77.77, visitor_ip=77.77.77.77, visitor_messages=2, visitor_messages_limit=17280, visitor_messages_remaining=17278, visitor_request_limiter_limit=0.2, visitor_request_limiter_tokens=60, visitor_seen=2024-10-21T23:42:10.041Z) 2024/10/21 23:42:10 DEBUG Access to topic st_1DxBLrCgXJYXZ not authorized (error=unauthorized, http_method=GET, http_path=/st_1DxBLrCgXJYXZ/ws?auth=QmVhcmVyIHRrX245NnE1OHk2anVieWx1MHFzdWZzaHlrcnoyNmR1, tag=http, topic=st_1DxBLrCgXJYXZ, topic_last_access=2024-10-21T23:29:00.992Z, topic_subscribers=0, user_id=u_11sCmqbbhZ, user_name=user1, visitor_auth_limiter_limit=0.016666666666666666, visitor_auth_limiter_tokens=30, visitor_id=ip:77.77.77.77, visitor_ip=77.77.77.77, visitor_messages=2, visitor_messages_limit=17280, visitor_messages_remaining=17278, visitor_request_limiter_limit=0.2, visitor_request_limiter_tokens=59.0000454276, visitor_seen=2024-10-21T23:42:10.041Z) 2024/10/21 23:42:10 DEBUG WebSocket error (this error is okay, it happens a lot): forbidden (error=forbidden, error_code=40301, http_method=GET, http_path=/st_1DxBLrCgXJYXZ/ws?auth=QmVhcmVyIHRrX245NnE1OHk2anVieWx1MHFzdWZzaHlrcnoyNmR1, http_status=403, tag=websocket, topic=st_1DxBLrCgXJYXZ, topic_last_access=2024-10-21T23:29:00.992Z, topic_subscribers=0, user_id=u_11sCmqbbhZ, user_name=user1, visitor_auth_limiter_limit=0.016666666666666666, visitor_auth_limiter_tokens=30, visitor_id=ip:77.77.77.77, visitor_ip=77.77.77.77, visitor_messages=2, visitor_messages_limit=17280, visitor_messages_remaining=17278, visitor_request_limiter_limit=0.2, visitor_request_limiter_tokens=59.0000614642, visitor_seen=2024-10-21T23:42:10.041Z) 2024/10/21 23:42:10 DEBUG HTTP request finished (http_method=GET, http_path=/st_1DxBLrCgXJYXZ/ws?auth=QmVhcmVyIHRrX245NnE1OHk2anVieWx1MHFzdWZzaHlrcnoyNmR1, tag=http, time_taken_ms=0, user_id=u_11sCmqbbhZ, user_name=user1, visitor_auth_limiter_limit=0.016666666666666666, visitor_auth_limiter_tokens=30, visitor_id=ip:77.77.77.77, visitor_ip=77.77.77.77, visitor_messages=2, visitor_messages_limit=17280, visitor_messages_remaining=17278, visitor_request_limiter_limit=0.2, visitor_request_limiter_tokens=59.000066507, visitor_seen=2024-10-21T23:42:10.041Z)

Here is a snippet of the server log when the PWA open and DOES update everything where the subscription topic (/appm1) is requested:

2024/10/21 23:54:29 DEBUG HTTP stream connection opened (http_method=GET, http_path=/appm1/json?poll=1&since=nhWgHwucvDop, tag=subscribe, user_id=u_11sCmqbbhZ, user_name=user1, visitor_auth_limiter_limit=0.016666666666666666, visitor_auth_limiter_tokens=30, visitor_id=ip:77.77.77.77, visitor_ip=77.77.77.77, visitor_messages=2, visitor_messages_limit=17280, visitor_messages_remaining=17278, visitor_request_limiter_limit=0.2, visitor_request_limiter_tokens=56.3817183308, visitor_seen=2024-10-21T23:54:29.42Z) 2024/10/21 23:54:29 DEBUG Access to topic st_1DxBLrCgXJYXZ not authorized (error=unauthorized, http_method=GET, http_path=/st_1DxBLrCgXJYXZ/json?poll=1, tag=http, topic=st_1DxBLrCgXJYXZ, topic_last_access=2024-10-21T23:29:00.992Z, topic_subscribers=0, user_id=u_11sCmqbbhZ, user_name=user1, visitor_auth_limiter_limit=0.016666666666666666, visitor_auth_limiter_tokens=30, visitor_id=ip:77.77.77.77, visitor_ip=77.77.77.77, visitor_messages=2, visitor_messages_limit=17280, visitor_messages_remaining=17278, visitor_request_limiter_limit=0.2, visitor_request_limiter_tokens=56.3817238494, visitor_seen=2024-10-21T23:54:29.42Z) 2024/10/21 23:54:29 DEBUG Connection closed with HTTP 403 (ntfy error 40301) (error=forbidden, error_code=40301, http_method=GET, http_path=/st_1DxBLrCgXJYXZ/json?poll=1, http_status=403, tag=http, topic=st_1DxBLrCgXJYXZ, topic_last_access=2024-10-21T23:29:00.992Z, topic_subscribers=0, user_id=u_11sCmqbbhZ, user_name=user1, visitor_auth_limiter_limit=0.016666666666666666, visitor_auth_limiter_tokens=30, visitor_id=ip:77.77.77.77, visitor_ip=77.77.77.77, visitor_messages=2, visitor_messages_limit=17280, visitor_messages_remaining=17278, visitor_request_limiter_limit=0.2, visitor_request_limiter_tokens=56.381962958799996, visitor_seen=2024-10-21T23:54:29.42Z) 2024/10/21 23:54:29 DEBUG HTTP request finished (http_method=GET, http_path=/st_1DxBLrCgXJYXZ/json?poll=1, tag=http, time_taken_ms=2, user_id=u_11sCmqbbhZ, user_name=user1, visitor_auth_limiter_limit=0.016666666666666666, visitor_auth_limiter_tokens=30, visitor_id=ip:77.77.77.77, visitor_ip=77.77.77.77, visitor_messages=2, visitor_messages_limit=17280, visitor_messages_remaining=17278, visitor_request_limiter_limit=0.2, visitor_request_limiter_tokens=56.3819924882, visitor_seen=2024-10-21T23:54:29.42Z) 2024/10/21 23:54:29 DEBUG HTTP stream connection closed (http_method=GET, http_path=/appm1/json?poll=1&since=nhWgHwucvDop, tag=subscribe, user_id=u_11sCmqbbhZ, user_name=user1, visitor_auth_limiter_limit=0.016666666666666666, visitor_auth_limiter_tokens=30, visitor_id=ip:77.77.77.77, visitor_ip=77.77.77.77, visitor_messages=2, visitor_messages_limit=17280, visitor_messages_remaining=17278, visitor_request_limiter_limit=0.2, visitor_request_limiter_tokens=56.3820618692, visitor_seen=2024-10-21T23:54:29.42Z)

:crystal_ball: Additional context

It seems the PWA is not always aware of the new push notifications so not requesting update for the relevant topics. How does the PWA determine when to request updates for each subscribed topic? Is there a way for users to force a full reload in the PWA launched from the home screen?

FYI, it does appear that sometimes after a while (>5 minutes) the PWA would eventually request update for the subscribed topic and display the new notification messages.

gw8484 commented 1 month ago

After some additional testing, it seems that notification also stops working after a while.

Not sure if this has been reported for ntfy but it appears there are some known issues with PWA on iOS (https://github.com/firebase/firebase-js-sdk/issues/8010). The main issue is seemingly random reset of web push registrations. So, I am guessing it could be causing weird problems in ntfy including the ones reported earlier.

Unfortunately, it looks like PWA is not quite ready for prime time on iOS. It's really too bad. I was hoping PWA could be a viable alternative to the native app on iOS. The great work on ntfy is much appreciated in any case.

wunter8 commented 1 month ago

Thanks for looking into it some more. I haven't heard of others having issues with the PWA on iOS, but we'll keep this in mind