Hi @Vlad WebKit team landed the fix for this. You can close this issue assuming you guys will pick up their main branch at some point.
I posted some more details here: https://bugs.webkit.org/show_bug.cgi?id=254777
But TL;DR; It's only MessagePort based transferables affected and if you exclude them from the
data
object the structed clone process works as expected. then you can access the MessagePort from the MessageEvent.ports[] array. It's less explicit, but it's a workaround I'm going to implement in my extension while this bug exists in WebKit.Just wanted to update this is a core Safari (or WebKit) bug. I'm seeing this behavior with Safari 16.4 as well.
My extension (https://chrome.google.com/webstore/detail/sauce-for-strava/eigiefcapdcdmncdghkeahgfmnobigha) uses a channel/ports to communicate between page scripts and the ext content script. To do this it uses the transfer argument of
postMessage
but when I use the transfer argument to postMessage the event handler gets an event with a nulldata
property.Steps to reproduce:
- Call
postMessage({foo: 'bar', port}, self.origin, [port])
from page script. - Add window.message event handler to an extension content script and evaluate the event callback arg.
- Observe the ev.data is null instead of
{foo: 'bar', port: port}
Incidentally I can see that a kagi based event listener is also getting this message and it also produces a console error because it assumes ev.data is an object.
Expected behavior:
For the message handler to get an event object with a non-nulldata
property filed with the contents sent from the postMessage caller.Orion, OS version; hardware type:
0.99.123.3-beta, macOS 13.2.1, MBP 2021 (arm64)