GoogleChromeLabs / GoogleChromeLabs/comlink

DataCloneError on proxied object

Open
#561 0 comments 7 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
12.8k
Forks
435
PR merge metrics
No merged PRs in 30d

Description

I have something somewhat similar to this:
```js
// iframe
function foo(ctx) {
// do something
}
Comlink.expose(foo, Comlink.windowEndpoint(window.parent));

// main browser
const iframe = /* get iframe */;
const foo = Comlink.wrap(Comlink.windowEndpoint(iframe.contentWindow));

const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');

foo(Comlink.proxy(ctx));
```

But when the last line runs, I get the error:
```
DataCloneError: Failed to execute 'postMessage' on 'MessagePort': CanvasRenderingContext2D object could not be cloned.
```
I've also tried creating a new object which only has the functions from `CanvasRenderingContext2D` (bound to the original object), and then tried to proxy them and/or the containing object, but with that I always got a similar error:

```
DataCloneError: Failed to execute 'postMessage' on 'MessagePort': function () { [native code] } could not be cloned.
```

Is there a way to fix this?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.