Skip to content
This repository was archived by the owner on Aug 21, 2026. It is now read-only.
This repository was archived by the owner on Aug 21, 2026. It is now read-only.

Naming and precise definition of event.sameOrigin #51

Closed

Description

@domenic

For the navigate event, the explainer currently defines sameOrigin as:

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

<a href="https://user:[email protected]/foo">click me</a>

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:

  1. 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.)

  2. 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.

  3. 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.

  4. 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)...

Activity

  1. added
    change
    on Mar 1, 2021
  2. annevk commented on Mar 2, 2021

    @annevk

    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.

  3. added a commit that references this issue on Mar 3, 2021
    35108eb
  4. added a commit that references this issue on Mar 4, 2021
    5920e01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    change

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions