Open JackieNiebling opened 4 years ago
I believe this is a known bug in chromium. See [crbug.com/869222]().
If the Chromium behaviour is considered wrong, is there any way to uniquely tie a notification to a tab in the browser, if the user has used fragment navigation in the page? If there is not, what purpose does the client.url then serve?
I'm not sure we explicitly considered the case of navigating a SPA.
You can achieve what you want by first finding windows that match the correct origin/path without fragment and then using postMessage() to ask them their current URL.
We may want to expose a client.currentURL
or something. @jakearchibald WDYT?
There's some overlap with https://github.com/w3c/ServiceWorker/issues/1475 here which had similar motivating use-cases discussed. (Specifically, Facebook deciding which existing tabs to navigate/focus in response to a notification being clicked, with particular concern on not interrupting an existing flow like composing a message, something which was not necessarily reflected dynamically into the URL.)
According to the spec, the service worker (window) client URL is the creation URL. Edge (44.18362.449.0) and Firefox (76.0.1) appears to adhere to this specification to the letter. Chrome (83.0.4103.61) returns the URL including any fragment that was added later by navigating within the page, in contrast to the other two.
This means that when comparing the client window URL to the URL from the event from a notificationclick, the comparison will work in Chrome and fail in FF and Edge, if the user navigated within the page using fragments after the page loaded.
There is an example on MDN that describes how to compare these two URLs to find the right window the notification is for. If the user has navigated on the page using a hash fragment in the meanwhile, this comparison will fail (in FF and Edge). While the spec for fragments is pretty clear that they form an intrinsic part of the URI, it also states that:
Which interpretation of the spec is correct here?