I'm passing an ImageBitmap into a webworker, to render on canvas and then generate a URL for loading into THREE.js on the main thread.
in the main thread
this.canvas = this.canvasEl.transferControlToOffscreen()
this.workerInstance.postMessage({canvas: this.canvas}, [this.canvas]);
...
createImageBitmap(this.img).then(imageData => {
this.imageBitmap = imageData
this.workerInstance.postMessage({image:imageData}, [imageData])
In the worker
_ctx.drawImage(image, 0, 0)
_canvas.convertToBlob({type: "image/png"}).then(blob => console.log(blob))
DOMException: Failed to execute 'convertToBlob' on 'OffscreenCanvas': Tainted "OffscreenCanvas" may not be exported.
The image on the main thread has crossorigin="anonymous"
. It also does have another image copied to it but this is same domain.
The image is created dynamically:
docString = '<svg width="' + this.width + '" height="' + this.height + '" xmlns="http://www.w3.org/2000/svg"><defs><style type="text/css"><![CDATA[a[href]{color:#0000EE;text-decoration:underline;}' + this.cssembed.join('') + ']]></style></defs><foreignObject x="0" y="0" width="' + this.width + '" height="' + this.height + '">' + parent[0] + docString + parent[1] + '</foreignObject></svg>';
this.img.src = "data:image/svg+xml;utf8," + encodeURIComponent(docString);
THe code is here https://github.com/supereggbert/aframe-htmlembed-component/blob/master/src/htmlcanvas.js
I'm updating it to use Offscreen canvas and web workers for faster renderering