Reuse the open PWA window when an email link launches the app - #154
Merged
Conversation
An alert email links at our own reader page, so on a device where the app handles its own links every click was a launch of rssamplifier.com within scope. The manifest declared no launch_handler, which leaves the browser on `auto` — and `auto` opens a new app window per launch. Somebody working through a digest ended up with one window per post. `navigate-existing` focuses the app window that was used most recently and navigates it to the launched URL instead, which is what the reader wants here: the link names a specific post, so arriving at that post in the window already open is the whole point. `auto` follows it in the list as the fallback for a browser that does not know the first value, and for the case there is no window open yet. Nothing else was needed. The notification click handler already reuses a window by hand (clients.matchAll, then focus and navigate) — that path never went through the launch handler, which is why push taps were fine and email links were not. Safari and Firefox ignore launch_handler and keep their current behaviour. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013FR5zDT4DGJAmwDb6oVZ6n
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.
The problem
Clicking a link in an alert email opened the installed PWA in a new window every time. Working through a digest left one app window per post.
Why
Alert emails link at our own reader page —
packages/notify/src/render.jsbuilds${origin}/{slug}/read?p={guid}— so every click is an in-scope launch ofrssamplifier.com.apps/web/public/manifest.webmanifestdeclared nolaunch_handler, which leaves the browser onauto, andautoopens a new app window per launch.The fix
navigate-existingfocuses the most recently used app window and navigates it to the launched URL. That is the right mode here rather thanfocus-existing: the email link names a specific post, so landing on that post in the window already open is the point.autofollows as the fallback for a browser that does not understand the first value, and for the case where no window is open yet.What did not need changing
The
notificationclickhandler insw.jsalready reuses a window by hand (clients.matchAll→focus→navigate). That path never went through the launch handler, which is why push taps were already fine and only email links were not.sw.jsVERSION goes v6 → v7 because/manifest.webmanifestis one ofSHELL_URLS, so the copy taken at install is now stale. That bump is hygiene, not the fix — nothing serves the cached manifest today (.webmanifestfalls through the fetch handler to the network), and the browser readslaunch_handlerover the network regardless.Compatibility
Chromium 110+ honours it. Safari and Firefox ignore
launch_handlerand keep their current behaviour, so nothing regresses there. iOS home-screen installs open email links in Safari rather than the app either way.Testing
manifest.webmanifestparses as valid JSON with the new keynode --check apps/web/public/sw.jspassesapps/web/test/proxy.test.jsonly checks that the proxy matcher skips these paths, unaffected)🤖 Generated with Claude Code
https://claude.ai/code/session_013FR5zDT4DGJAmwDb6oVZ6n