2

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 null data property.

Steps to reproduce:

  1. Call postMessage({foo: 'bar', port}, self.origin, [port]) from page script.
  2. Add window.message event handler to an extension content script and evaluate the event callback arg.
  3. 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-null data 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)

    6 days later
    11 days later

    Just wanted to update this is a core Safari (or WebKit) bug. I'm seeing this behavior with Safari 16.4 as well.

      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.

      • Vlad replied to this.
        19 days later
        15 days later
        No one is typing