Skip to content

Conversation

@mikewest
Copy link
Member

@mikewest mikewest commented Dec 4, 2025

whatwg/html#11846 added an Origin interface, which relies on an "extract an origin" operation to support the creation of new Origin objects via Origin.from(...). This PR defines that operation for URL objects.

Addresses a remaining portion of whatwg/html#11534.

(See WHATWG Working Mode: Changes for more details.)


Preview | Diff

whatwg/html#11846 added an `Origin` interface, which
relies on an "extract an origin" operation to support the creation of new `Origin`
objects via `Origin.from(...)`. This PR defines that operation for `URL` objects.

Addresses a remaining portion of whatwg/html#11534.

<div algorithm>
<p>Objects implementing the {{URL}} interface's <a for="platform object">extract an origin</a> steps are
to return <a>this</a>'s <a for=URL>URL</a>'s <a for=url>origin</a>. [[!HTML]]
Copy link
Member

Choose a reason for hiding this comment

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

I think it's a little weird that we use "this" here, but it's probably okay.

Copy link
Member Author

Choose a reason for hiding this comment

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

This mirrors what we did in HTML (e.g. https://html.spec.whatwg.org/multipage/browsers.html#the-origin-interface:extract-an-origin and https://html.spec.whatwg.org/multipage/webappapis.html#windoworworkerglobalscope-mixin:extract-an-origin). We could replace it with something like "the object's" throughout if that would be preferable?

Co-authored-by: Anne van Kesteren <annevk@annevk.nl>
@annevk
Copy link
Member

annevk commented Dec 4, 2025

WPT comments:

  • You can't create new content in WPT /interfaces/. That directory is managed automatically. It should probably be tested as part of other html.idl APIs, though perhaps it can be split, but it'll have to load html.idl.
  • It seems like we don't have tests for <a> and <area> without href attributes. From a quick skim I suspect this might not be implemented correctly.

@mikewest
Copy link
Member Author

mikewest commented Dec 5, 2025

You can't create new content in WPT /interfaces/. That directory is managed automatically. It should probably be tested as part of other html.idl APIs, though perhaps it can be split, but it'll have to load html.idl.

You're right, I didn't think about this when we moved Origin into HTML. I'll fix it up once the file's updated (https://github.com/w3c/webref/blob/main/ed/idl/html.idl is up to date, but hasn't been pulled in yet...).

It seems like we don't have tests for <a> and <area> without href attributes. From a quick skim I suspect this might not be implemented correctly.

I can add those, thanks for the suggestion!

@mikewest
Copy link
Member Author

mikewest commented Dec 5, 2025

It seems like we don't have tests for <a> and <area> without href attributes. From a quick skim I suspect this might not be implemented correctly.

I can add those, thanks for the suggestion!

You were right; Chromium's implementation was returning an opaque origin rather than throwing on Origin.from(<a>). Fixing that and updating the tests in https://chromium-review.googlesource.com/c/chromium/src/+/7231346.

brave-builds pushed a commit to brave/chromium that referenced this pull request Dec 5, 2025
When extracting an origin from `<a>` and `<area>` elements without an
`href` attribute, we're currently returning an opaque `Origin`. We
should throw instead, as there's not an origin to extract from these
elements (see [1]). Thanks to @annevk for pointing this out in [2].


[1]: https://html.spec.whatwg.org/multipage/links.html#api-for-a-and-area-elements:extract-an-origin
[2]: whatwg/url#892 (comment)

Bug: 434131026
Change-Id: I136cc0ff24355e29418e060ab384938f3615a60e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7231346
Commit-Queue: Mike West <mkwst@chromium.org>
Reviewed-by: Antonio Sartori <antoniosartori@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1554582}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Dec 5, 2025
When extracting an origin from `<a>` and `<area>` elements without an
`href` attribute, we're currently returning an opaque `Origin`. We
should throw instead, as there's not an origin to extract from these
elements (see [1]). Thanks to @annevk for pointing this out in [2].

[1]: https://html.spec.whatwg.org/multipage/links.html#api-for-a-and-area-elements:extract-an-origin
[2]: whatwg/url#892 (comment)

Bug: 434131026
Change-Id: I136cc0ff24355e29418e060ab384938f3615a60e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7231346
Commit-Queue: Mike West <mkwst@chromium.org>
Reviewed-by: Antonio Sartori <antoniosartori@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1554582}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Dec 5, 2025
When extracting an origin from `<a>` and `<area>` elements without an
`href` attribute, we're currently returning an opaque `Origin`. We
should throw instead, as there's not an origin to extract from these
elements (see [1]). Thanks to @annevk for pointing this out in [2].

[1]: https://html.spec.whatwg.org/multipage/links.html#api-for-a-and-area-elements:extract-an-origin
[2]: whatwg/url#892 (comment)

Bug: 434131026
Change-Id: I136cc0ff24355e29418e060ab384938f3615a60e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7231346
Commit-Queue: Mike West <mkwst@chromium.org>
Reviewed-by: Antonio Sartori <antoniosartori@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1554582}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants