You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 21, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 21, 2026. It is now read-only.
Naming and precise definition of event.sameOrigin #51
a convenience boolean indicating whether the navigation is same-origin, and thus will stay in the same app history or not. (I.e., this is (new URL(e.destination.url)).origin === self.origin.)
However, there's a very closely related concept, which is "can you call respondWith()". This is not exactly the same. You can call respondWith() whenever the URL only differs in path/query/fragment components. (The same conditions as history.pushState().)
The difference is cases like https://example.com/foo and https://user:[email protected]/foo. These are same-origin, but they differ in components beyond just path/query/fragment. So this means we cannot allow navigate handlers to intercept
on https://example.com/ pages.
So: this means code such as
if(event.sameOrigin){event.respondWith(...)}
will fail in such edge cases.
I see a few paths:
Keep the name and the semantics of event.sameOrigin. Code that is using credentialed URLs could get a failure when it calls respondWith(), but that's fine; it's a strange edge case. (Credentialed URLs are basically deprecated on the web.)
Keep the name of event.sameOrigin, but change the semantics to be about path/query/fragment-differences-only. This makes me uneasy because "same-origin" is a very well-defined concept and it'd be unfortunate to lie in such a way.
Change the name and semantics, to e.g. event.canRespond. This makes the code a bit less self-documenting, i.e. if (event.canRespond) { event.respondWith(...) } is less obvious to the reader than if (event.sameOrigin) { event.respondWith(...) }. But oh well.
Keep event.sameOrigin and also introduce event.canRespond.
Note that for (2) and (3), we lose the ability to easily know whether the destination will end up in the same app history list, since that is origin-based. One would have to do the long test, i.e. new URL(e.destination.url)).origin === self.origin. I'm not sure if there's a strong use case for that though.
(Hmm, maybe we should change app history's scoping to use path/query/fragment-differences-only, instead of origin?? That gives the nice property that anything in your app history list, you can intercept with respondWith() and convert to a single-page nav... that change would be orthogonal though, I think.)
Anyway, I lean toward (3). Any other thoughts? /cc @annevk to see what he thinks of (2)...
Is "whenever the URL only differs in path/query/fragment components" a good condition? I guess it means you cannot push a blob: URL either, which is probably good. Not sure why username/password cannot be exposed though as they are visible to the script anyway, but maybe we don't want to allow navigating to them through new APIs.
Overall canRespond seems preferable to me as it indicates there are considerations there beyond same-origin (which I think is kinda obvious), but at some point I'd also like to explore those specifics I suppose.
Activity
annevk commentedon Mar 2, 2021
Is "whenever the URL only differs in path/query/fragment components" a good condition? I guess it means you cannot push a
blob:URL either, which is probably good. Not sure why username/password cannot be exposed though as they are visible to the script anyway, but maybe we don't want to allow navigating to them through new APIs.Overall
canRespondseems preferable to me as it indicates there are considerations there beyond same-origin (which I think is kinda obvious), but at some point I'd also like to explore those specifics I suppose.Revamp when navigate fires, is cancelable, and is respond-able
Revamp when navigate fires, is cancelable, and is respond-able