Issue with using comlink for ext host ↔︎ webview communication (postMessage missing "transfers" parameter) #2392
Unanswered
darknoon
asked this question in
Extension Development QnA
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm trying to use the popular Comlink IPC abstraction to simplify my webview ↔︎ custom editor communication.
It allows you to make abstractions for the (addList…/removeList…/postMess…) interface
Webview side, which roughly looks like this
On the Extension Host side, I use
webview.onDidReceiveMessage(…)
andwebview.postMessage
to provide the same API (this is theextensionHostEndpoint()
function above.This all works great until I want to go the other way, sending a message from the extension host → webview via
Comlink.proxy(…)
Unfortunately, Comlink likes to create additional
MessagePort
s in order to make it easier to proxy objects from one side of the IPC to the other.VSCode bug
This runs up against what appears to be a bug in vscode, where you can't pass a
MessagePort
from the Webview side back to the extension host (or transfers in general it seems)I made a minimal repro so you can see that issue
Why is this broken?
The support code in
aquireVsCodeApi()
seems to supporttransfers
, but at the last moment doesn't actually pass them through. I got a little bit confused due to the amount of indirection and 2 iframes being involved, butthe rough call chain is
new MessageChannel()
→vscode.postMessage({port: port1}, port1)
→→
doPostMessage('onmessage', {message, transfer: [MessagePort]}, transfer)
→HostMessaging.postMessage(channel, data, undefined)
→port1.postMessage({channel, data}, undefined);
Could this be intentional somehow? Either way the code looks like it intends to pass transfers but doesn't so maybe it could be clarified if this is supposed to work on not.
perhaps related: microsoft/vscode#206884
Beta Was this translation helpful? Give feedback.
All reactions