Currently, I am implementing a process where an ImageBitmap is passed into a web worker in order to render it on a canvas. Subsequently, a URL is generated for loading into THREE.js on the main thread.
Within 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])
Inside the worker
_ctx.drawImage(image, 0, 0)
_canvas.convertToBlob({type: "image/png"}).then(blob => console.log(blob))
Encountered a DOMException: Failed to execute 'convertToBlob' on 'OffscreenCanvas': The "OffscreenCanvas" in use may not be exported.
The image on the main thread is marked with crossorigin="anonymous"
. Another image is also added to it, but both are from the same domain.
This image is dynamically created:
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);
You can view the code here.
I am currently in the process of updating the code to utilize Offscreen canvas and web workers for improved rendering performance.