Skip to content

Focus the sending web app when a Chromium notification is clicked - #14555

Closed
omarchybot wants to merge 3 commits into
quattrofrom
fix/issue-7260
Closed

omarchybot wants to merge 3 commits into
quattrofrom
fix/issue-7260

Conversation

@omarchybot

Copy link
Copy Markdown
Collaborator

Clicking a notification from a Chromium web app never reaches the web app. Chromium-derived browsers send every web notification under their own app name (Chromium, Brave Origin), and the shell reaches the sender's window through omarchy-hyprland-focus-app "<app name>", which takes the first window whose class matches that name. That is the plain browser window, or nothing at all when the name has a space in it, as Brave's does. And for a live toast the click never even gets that far: Chromium registers a default action, so invokePopupDefault() invokes it and skips the fallback, but Chromium raises no window in response, because the shell hands it no activation token. On a clean worker (Hyprland 0.56.2, Chromium 152) the click emits ActionInvoked "default", Hyprland sees no event at all, and focus stays where it was.

What identifies the sender is the link Chromium leads the body with: <a href="https://teams.microsoft.com/">teams.microsoft.com</a>. Its host is the same one Chromium puts in the web app's window class, chrome-teams.microsoft.com__-Default (brave-… for Brave; any path and the profile follow the __; the port is dropped). So:

  • NotificationLogic.webAppHost() reads that host from the body's leading link, only for a sender isChromiumDerived() already recognises (the same check sanitizeBody() uses to strip that link from the toast).
  • omarchy-hyprland-focus-app takes the host as an optional second argument and first looks for a window whose class names exactly that host, then falls back to the app name as before. A one-argument call, as omarchy-launch-browser makes, behaves as it did.
  • invokePopupDefault() focuses through the host whenever it has one, even after invoking the default action, since that action raises nothing on its own.

A notification from an ordinary browser tab carries the same link. With no web app open for that site it now focuses the browser, where before the click did nothing. When the same site is open as a web app in two Chromium browsers or profiles, the first window wins: Chromium and Google Chrome both name web app windows chrome-<host>__…, so the notification carries nothing to tell them apart.

Fixes #7260
Fixes #9707

Reviewed by Claude Opus 5.5 and Codex Medium.

omarchybot and others added 3 commits October 8, 2026 10:13
Chromium-derived browsers notify under their own name for every web app, so the click fallback matched the plain browser window by class. Read the sending origin's host from the link Chromium leads the body with and match it against the web app's window class first. Chromium's own default action raises no window here, since it gets no activation token, so do this even when that action was invoked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A substring match on -<host>__ also took chrome-not-<host>__ for <host>. Compare the class's host part instead. Assert that Service.qml passes the host on a click even after the default action, since the logic tests alone stay green without it.

Co-Authored-By: Codex Medium <noreply@openai.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
split on an empty class yields no first element, and sub() on null aborts the whole match, so a classless window listed first stopped every click from focusing anything.

Co-Authored-By: Codex Medium <noreply@openai.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Medium risk] Adds web app host detection to notification click handling.

The PR appears safe to merge, with a non-blocking suggestion to prevent unrelated window classes from matching the host.

Findings

  1. P2 Unrelated windows can match ▶

Summary

The PR reads the sending host from Chromium notification bodies and passes it to omarchy-hyprland-focus-app. Notification clicks now try the matching web app before the existing app-name fallback, even after invoking a default action.

  • Live and replayed notifications share this behavior.
  • The host match should also check that the window class belongs to a browser web app.
  • Known limitation acknowledged by omarchybot: when multiple browsers or profiles have the same site's web app open, the first matching window wins because the notification does not identify the browser or profile.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Notification clicked] --> B[invokePopupDefault]
  B --> C[Invoke available default action]
  C --> D[Read webAppHost from raw body]
  D --> E{Host found or no action invoked?}
  E -->|Yes| F[omarchy-hyprland-focus-app]
  F --> G{Host matches a window class?}
  G -->|Yes| H[Focus first matching window]
  G -->|No| I[Try existing app-name fallback]
  E -->|No| J[Dismiss popup]
  H --> J
  I --> J
Loading

Reviews (1) · Last reviewed commit: "Keep the host match going past a window ..." · Reviewed by Greptile

jq -r --arg pattern "$app" --arg host "$web_app_host" \
'def matches($value): ($value // "") | test($pattern; "i");
first(
(.[] | select($host != "" and ((.class // "") | ascii_downcase | (split("__")[0] // "") | sub("^[a-z]+-"; "")) == $host)),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Unrelated windows can match

The new host match also accepts non-browser classes such as teams.microsoft.com or custom-teams.microsoft.com. If such a window appears before the sending web app, clicking the notification focuses that unrelated window instead.

Require a supported browser prefix and the __ separator. Add a test with an unrelated matching class before the web app.

@omarchybot

Copy link
Copy Markdown
Collaborator Author

Read the diff at a8e97c7 against quattro, along with #7260 and #9707, which it closes. Nothing ran on a worker this pass: the item stopped at classification.

The classification is unsettled, so this gets no class label for now. Claude Opus 5.5 classified it as a bug. Clicking a web app's notification is meant to focus that web app, and on quattro it focuses the plain browser window, or nothing when the browser's name has a space in it. Both linked issues report it that way. Codex Medium, asked separately, classified it as an enhancement. Its likely reading is that matching windows by the sending site's host is new behaviour rather than a repair of the old. The maintainer settles this, or a tie-break does. Until then it is not verified and gets no ready.

It also no longer merges cleanly into quattro. #14441 (9f49906) changed bin/omarchy-hyprland-focus-app to sort clients by focusHistoryID before matching, and added a test in the same spot in test/shell.d/hyprland-focus-app-test.sh. The conflict is mechanical: keep the sort, the host match and both tests. With the sort in place, the host match also takes the most recently focused window when one site is open as a web app in two browsers or profiles. The description here says "the first window wins", so that line will need updating when the conflict is resolved.

Waiting on the maintainer.

@ryanrhughes

Copy link
Copy Markdown
Collaborator

Thanks @omarchybot! The new notification engine (#15932) rewrote click routing: exec hint, then the sender's default action, then the sender's window by pid, then a window showing the source (exact class, or a browser window whose title names the site), then the site itself. Web app windows are matched by host (chrome-<host> classes) now. The catch is that Chromium registers a default action, which runs first, and with no activation token it may not raise anything. allowDefaultActionOnCardClick: false goes straight to the host match. This branch can't be rebased onto it, so I'm closing it, but thanks for the detailed write-up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants