Re: [w3c/ServiceWorker] Client postmessage uses MessageEvent (Issue #1823)

asutherland left a comment (w3c/ServiceWorker#1823)

[In the MessageEvent WebIDL](https://html.spec.whatwg.org/multipage/comms.html#messageevent) MessageEventSource is defined to be allowed to include ServiceWorker and is the type of source.
```webidl
readonly attribute MessageEventSource? source;
...
typedef (WindowProxy or MessagePort or ServiceWorker) MessageEventSource;
```

For the [source definition](https://html.spec.whatwg.org/multipage/comms.html#dom-messageevent-source) it does seem like the "it represents" portion should indeed be expanded to explain the ServiceWorker case because it's at the very least misleading to not have it there.

Pedantically speaking, is the "It represents" normative?  Like it does seem like `The source attribute must return the value it was initialized to.` is a stronger statement than the "It represents" that is failing to be exhaustive.  And the text in [the ServiceWorker Client.postMessage algorithm](https://w3c.github.io/ServiceWorker/#client-postmessage-options) does explicitly initialize it:
> Let source be the result of [getting the service worker object](https://w3c.github.io/ServiceWorker/#get-the-service-worker-object) that represents contextObject’s [relevant global object](https://html.spec.whatwg.org/multipage/webappapis.html#concept-relevant-global)’s [service worker](https://w3c.github.io/ServiceWorker/#serviceworkerglobalscope-service-worker) in targetClient.
> ...
> [Dispatch an event](https://dom.spec.whatwg.org/#concept-event-dispatch) named [message](https://html.spec.whatwg.org/multipage/indices.html#event-message) at destination, using [MessageEvent](https://html.spec.whatwg.org/multipage/comms.html#messageevent), with its [origin](https://html.spec.whatwg.org/multipage/comms.html#concept-messageevent-origin) initialized to origin, the [source](https://html.spec.whatwg.org/multipage/comms.html#dom-messageevent-source) attribute initialized to source, the [data](https://html.spec.whatwg.org/multipage/comms.html#dom-messageevent-data) attribute initialized to messageClone, and the [ports](https://html.spec.whatwg.org/multipage/comms.html#dom-messageevent-ports) attribute initialized to newPorts.

Which is all to say, it seems like the ServiceWorker spec is maybe fine but the HTML spec should have that piece enhanced?

-- 
Reply to this email directly or view it on GitHub:
https://github.com/w3c/ServiceWorker/issues/1823#issuecomment-4546123859
You are receiving this because you are subscribed to this thread.

Message ID: <w3c/ServiceWorker/issues/1823/4546123859@github.com>

Received on Tuesday, 26 May 2026 16:21:40 UTC