fix: support postMessage options overload and handle transferable clone failures in Firefox#3078
Conversation
…ne failures
MessageSandbox.postMessage previously did not support the modern
postMessage(message, { targetOrigin, transfer }) overload, silently
dropping such calls. This broke iframe communication for applications
using the options-based API.
Additionally, in Firefox the Hammerhead message envelope can cause
DataCloneError ("MessagePort object could not be cloned") when
transferable objects are present in the transfer list. The structured
clone algorithm in Firefox fails to reconcile the wrapped message
with the original transfer list.
This commit:
- Adds support for the postMessage(message, options) overload by
detecting an object second argument and extracting targetOrigin
and transfer from it.
- Wraps the fastApply call in a try/catch so that when structured
clone fails (e.g. Firefox with MessagePort transfers), the
original unwrapped message is sent as a fallback.
- Updates the receiving side (MessageEvent.data getter and
_onWindowMessage) to pass through messages that do not carry the
Hammerhead user-message envelope, since they may arrive from the
fallback path.
- Updates tests to cover the options overload and adjusts the
existing "object as targetOrigin" test to reflect the new
behavior.
Made-with: Cursor
|
Thank you for your contribution to TestCafe. When a member of the TestCafe team becomes available, they will review this PR. |
|
Hi @crisryantan, We appreciate your contribution. I checked your changes and came to the conclusion that it's not necessary to make an additional handling for |
Align with maintainer feedback by keeping the postMessage options overload support while removing the extra MessagePort clone-error fallback path and related fallback handling. Made-with: Cursor
Keep upstream diagnostic behavior and inline note context while preserving the maintainer-requested removal of clone-error fallback handling. Made-with: Cursor
Thanks! Can you please take a look again 🙏 |
Closes #3077
Problem
MessageSandbox.postMessagedid not support the modernpostMessage(message, { targetOrigin, transfer })overload.When the second argument was an object, the call was treated as invalid and returned early, so messages were not delivered.
This also caused issues for
MessageChannel-based communication in Firefox, because the options object (which may includetransfer) was being handled astargetUrlinstead of a proper overload shape.Solution
1. Support the
postMessage(message, options)overloadpostMessagenow detects when the second argument is an object and delegates to_postMessageWithOptionsOverload.2. Handle options and transferables using native semantics
_postMessageWithOptionsOverload:targetOriginfrom options (falls back to current origin when missing),targetOrigin: '*'so transferable handling remains native.3. Keep legacy signature behavior intact
The existing wrapped flow for
postMessage(message, targetOrigin, transfer?)remains in place.Per maintainer feedback, the additional clone-error fallback path and related receive-side handling were removed.
Tests
postMessage(message, { targetOrigin })options overload.postMessage(message, { targetOrigin, transfer })withMessagePort.Made with Cursor