Skip to content

Open the notification URL when a notification is clicked while the app is already open - #100

Merged
luke- merged 1 commit into
masterfrom
fix/1263-notification-click-navigation
Jul 14, 2026
Merged

Open the notification URL when a notification is clicked while the app is already open#100
luke- merged 1 commit into
masterfrom
fix/1263-notification-click-navigation

Conversation

@luke-

@luke- luke- commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

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 notificationclick handler in the PWA service worker, before Firebase's importScripts, 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 a postMessage the 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 from Events.php into a new ServiceWorkerService.

Behavior matrix

Platform / state Before After
Desktop, app closed opens app, no navigation to URL ✅ opens URL
Desktop, tab open focuses tab, no navigation ✅ navigates to URL
Android PWA, closed or open focuses app, no navigation ✅ navigates to URL
iOS PWA, app closed focuses app, no navigation ✅ navigates to URL
iOS PWA, app already running focuses app, no navigation ⚠️ unchanged (see below)

Intentionally not covered: iOS PWA already running

When the PWA is already running, iOS never dispatches notificationclick to 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.

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).
@luke-
luke- merged commit 876f19f into master Jul 14, 2026
2 checks passed
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