Open the notification URL when a notification is clicked while the app is already open - #100
Merged
Merged
Conversation
Firebase's own notificationclick handler only focuses an already-open window without navigating it. Register our own handler before Firebase's importScripts that focuses and navigates (or opens a new window). Deterministic subset of PR #99 by Marc Farré, without the page-side heuristic for iOS PWAs that are already running (WebKit never dispatches notificationclick there).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Alternative to #99 — the deterministic subset of @marc-farre's work there. All credit for the root-cause analysis and the handler code goes to him; this PR only trims it down.
Ref: https://github.com/humhub/humhub-internal/issues/1263
What it does
Registers our own
notificationclickhandler in the PWA service worker, before Firebase'simportScripts, so it runs first. It fixes the actual Firebase SDK bug: Firebase's handler only focuses an already-open window without navigating it (it delegates navigation to apostMessagethe page never listens for). Our handler focuses and navigates, or opens a new window if none exists.Also includes
skipWaiting()/clients.claim()so updated service workers activate immediately (iOS otherwise keeps old ones alive for a long time), and extracts the service worker addon JS fromEvents.phpinto a newServiceWorkerService.Behavior matrix
Intentionally not covered: iOS PWA already running
When the PWA is already running, iOS never dispatches
notificationclickto the service worker at all (WebKit bug, iOS 17/18) — no service-worker code can ever see the tap. #99 explores a page-side heuristic for this case (IndexedDB pending-URL tracking + visibility/poll resolution). Per the discussion in the internal issue, that part is left out here: it relies on undocumented WebKit behavior, needs re-testing with every iOS release, and cannot distinguish tapping from dismissing a notification. Users who need reliable push behavior on iOS have the mobile app; once Apple fixes the event dispatch, this PR's handler covers that case automatically.