This is a live example of how to get rasterized SVG in WebWorker
without blocking the main thread:
- In the main thread, we create a new MessageChannel
-
Then, in the same main thread, we create a web worker and an Iframe
and forward the MessageChannel ports (part1 and part2) to them.
-
WebWorker passes the necessary data to an Iframe, in which the SVG is
converted to a raster and sent as an ImageBitmap back to WebWorker.
For clarity, the rasterized image is passed to the main thread and
displayed on the canvas
Read more in this article (original lang = rus, use a translator)
See result (below it should be a canvas with a smiley face):