Closed Bug 1345943 Opened 5 years ago Closed 5 years ago

Client.postMessage() should set the correct MessageEvent.source


(Core :: DOM: Service Workers, enhancement)

Not set



Tracking Status
firefox55 --- fixed


(Reporter: bkelly, Assigned: bkelly)




(2 files)

While working on bug 1293277 I noticed that we always set the MessageEvent.source to the service worker controlling the Client.

This was probably correct back when Clients.matchAll() only ever returned controlled Client objects.  We can now, however, use `includeUncontrolled:true` to access a Client from a ServiceWorker that does not control the Client.

I'm going to fix this separately so I can write and land a test.
This makes us try to set the MessageEvent.source to the same service worker that called Clients.postMessage().  Right now we have to look it back up via SWM, but I expect to change this soon in bug 1293277.
Attachment #8845702 - Flags: review?(bugmail)
This patch adds a WPT test that verifies we get the correct MessageEvent.source for different ServiceWorkers.  We fail this on current mozilla-central because we only return the controller and therefore MessageEvent.source is null.  After the P1 patch we pass this test.
Attachment #8845704 - Flags: review?(bugmail)
Attachment #8845702 - Flags: review?(bugmail) → review+
Comment on attachment 8845704 [details] [diff] [review]
P2 Add WPT verifying MessageEvent.source is set correctly when sent from waiting ServiceWorker. r=asuth

Review of attachment 8845704 [details] [diff] [review]:

A most excellent test.

Restating, the test:
- Lines up `script` and `script+?update'` in the registration's active and waiting slots, respectively.  An iframe holds `script` active.
- Messages the waiting and active scripts which echo the received data back, with the test asserting the source is correct.  The string payloads of 'waiting' and 'active' are for debugging support.
Attachment #8845704 - Flags: review?(bugmail) → review+
Pushed by
P1 Set the MessageEvent.source to ServiceWorker that called Client.postMessage(). r=asuth
P2 Add WPT verifying MessageEvent.source is set correctly when sent from waiting ServiceWorker. r=asuth
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla55
You need to log in before you can comment on or make changes to this bug.