Bug 259362 - window.postMessage with OffscreenCanvas is broken with isolated world message listener
Summary: window.postMessage with OffscreenCanvas is broken with isolated world message...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit API (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2023-07-20 10:42 PDT by Ali Juma
Modified: 2023-07-31 22:22 PDT (History)
6 users (show)

See Also:


Attachments
Test app (93.29 KB, application/zip)
2023-07-20 10:42 PDT, Ali Juma
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ali Juma 2023-07-20 10:42:39 PDT
Created attachment 467080 [details]
Test app

Using postMessage with an OffscreenCanvas breaks when there is a `message` event listener in an isolated world, even for main-world event listeners.

In practice, this bug causes web-exposed breakage on Chrome for iOS, which injects a `message` event listener into an isolated world as part of implementing browser features.

Steps to reproduce (also see the attached test app):
1) In an isolated world (e.g., WKContentWorld.defaultClientWorld) add a trivial `message` event listener that does anything at all with message.data.
2) In the page world, in an iframe, add a `message` event listener
3) In the page world, in the main frame, using a handle to the iframe's contentWindow, call postMessage with an OffscreenCanvas object.

Expect result:
The iframe's page world event listener successfully receives the message sent in (3).

Actual result:
The iframe's page world event listener receives `null`.

The attached test app demonstrates this bug, using four different message types to better illustrate the expected behavior, showing that postMessage works with Object, ArrayBuffer, and MessagePort, but not with OffscreenCanvas.

Bug 254777 fixed the MessagePort case.
Comment 1 Radar WebKit Bug Importer 2023-07-20 13:45:45 PDT
<rdar://problem/112618195>
Comment 2 Chris Dumez 2023-07-21 16:10:03 PDT
Pull request: https://github.com/WebKit/WebKit/pull/16003
Comment 3 EWS 2023-07-31 22:22:27 PDT
Committed 266465@main (acece69bd261): <https://commits.webkit.org/266465@main>

Reviewed commits have been landed. Closing PR #16003 and removing active labels.