Skip to content

Conversation

@waynemsmith
Copy link

Summary

This fixes two issues that prevent users from receiving push notifications after their browser subscription expires:

  • Add pushsubscriptionchange handler to service worker - When browsers invalidate/expire a push subscription (Safari does this aggressively, often within 24-72 hours), they fire this event. The handler automatically re-subscribes and syncs with the server.

  • Show subscribe button when permission granted but no subscription exists - Previously, if permission was "granted" but the subscription expired, the UI showed "Push notifications are OFF" but no button to re-subscribe. Users were stuck unable to re-enable notifications.

Problem

Safari is known to expire push subscriptions after periods of inactivity. When this happens:

  1. The pushsubscriptionchange event fires in the service worker
  2. Without a handler, nothing happens client-side
  3. Server attempts to push to the old endpoint → Apple rejects it
  4. Server catches ExpiredSubscription and deletes the subscription
  5. User sees "OFF" but can't re-subscribe because the button is hidden (permission is still "granted")

Test plan

  • Enable push notifications in Safari
  • Wait for subscription to expire (or manually unsubscribe via DevTools)
  • Verify the "Turn ON push notifications" button appears
  • Click to re-subscribe
  • Verify notifications work again

🤖 Generated with Claude Code

This fixes two issues that prevent users from receiving push notifications
after their browser subscription expires (common with Safari):

1. Add pushsubscriptionchange handler to service worker
   - When browsers invalidate/expire a push subscription, they fire this event
   - Safari is particularly aggressive about expiring subscriptions
   - The handler automatically re-subscribes and syncs with the server

2. Show subscribe button when permission granted but no subscription exists
   - Previously, if permission was "granted" but the subscription expired,
     the UI showed "OFF" but no button to re-subscribe
   - Users were stuck unable to re-enable notifications
   - Now the button appears when subscription is missing regardless of
     permission state

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant