Skip to content

Teach ExtendableMessageEvent to work with origins.#1821

Merged
yoshisatoyanagisawa merged 3 commits intow3c:mainfrom
mikewest:extendablemessageevent-origin
Mar 12, 2026
Merged

Teach ExtendableMessageEvent to work with origins.#1821
yoshisatoyanagisawa merged 3 commits intow3c:mainfrom
mikewest:extendablemessageevent-origin

Conversation

@mikewest
Copy link
Copy Markdown
Member

@mikewest mikewest commented Mar 10, 2026

Currently, ExtendableMessageEvent's origin holds a serialized origin. In order for Origin.from(...) to function as intended for sources with opaque origins, we need to hold an origin on ExtendableMessageEvent instead.

This patch adds an "origin" concept to ExtendableMessageEvent, and shifts call sites to initialize that value with an origin whenever possible. It also adds "extract an origin" steps to return the stored origin when present, and to return null in cases where the object was initialized with an untrusted origin representation (e.g., when its constructor is called with a ExtendableMessageEventInit dictionary).

This replicates whatwg/html#11993's work on MessageEvent, and should fix #1820.


Preview | Diff

Currently, ExtendableMessageEvent's origin holds a serialized origin. In
order for Origin.from(...) to function as intended for sources with opaque
origins, we need to hold an origin on ExtendableMessageEvent instead.

This patch adds an "origin" concept to `ExtendableMessageEvent`, and shifts
call sites to initialize that value with an origin whenever possible. It
also adds "extract an origin" steps to return the stored origin when present,
and to return null in cases where the object was initialized with an
untrusted origin representation (e.g., when its constructor is called with a
ExtendableMessageEventInit dictionary).

This replicates whatwg/html#11993's work on `MessageEvent`, and should
fix w3c#1820.
Copy link
Copy Markdown
Member

@annevk annevk left a comment

Choose a reason for hiding this comment

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

This looks good to me. A Service Worker editor should probably do final approval.

index.bs Outdated
text: visibilityState; for: Document; url: page-visibility
type: dfn
urlPrefix: comms.html
text: concept-MessageEvent-origin; url: concept-messageevent-origin
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should probably export this.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I didn't expect anyone outside HTML would need it. Silly me. I'll send you a PR in a minute to add the attribute.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ah. Actually we did export it. I guess it just hasn't landed in the references DB yet. We should be able to drop this ~tomorrow.

@yoshisatoyanagisawa
Copy link
Copy Markdown
Collaborator

Thanks for the update. To ensure full parity with the changes made to MessageEvent in whatwg/html#12235, I was looking for the "extract an origin" steps for ExtendableMessageEvent.

Since ExtendableMessageEvent doesn't inherit from MessageEvent, we'll need an explicit definition to support the Origin.from() API. Should we add a sentence similar to the one in the HTML spec here as well?

@mikewest
Copy link
Copy Markdown
Member Author

Thanks for pointing that out. Added it in c890bb1.

@yoshisatoyanagisawa
Copy link
Copy Markdown
Collaborator

lgtm. Thank you!

@yoshisatoyanagisawa yoshisatoyanagisawa self-requested a review March 12, 2026 00:57
@yoshisatoyanagisawa yoshisatoyanagisawa merged commit c9b4790 into w3c:main Mar 12, 2026
2 checks passed
github-actions bot added a commit that referenced this pull request Mar 12, 2026
SHA: c9b4790
Reason: push, by yoshisatoyanagisawa

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
github-actions bot added a commit to asleekgeek/ServiceWorker that referenced this pull request Mar 12, 2026
SHA: c9b4790
Reason: push, by pull[bot]

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@mikewest mikewest deleted the extendablemessageevent-origin branch March 12, 2026 06:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Origin API: need to change ExtendableMessageEvent

3 participants