Summary
Canvas rendering in Worker — off main thread for games, charts, image processing. Transfer control from DOM canvas or create offscreen. No direct DOM from worker — post bitmap or use WebGL. Fallback when unsupported: main thread canvas.
Code example
const offscreen = canvas.transferControlToOffscreen();
worker.postMessage({ canvas: offscreen }, [offscreen]);
// In worker:
self.onmessage = (e) => {
const ctx = e.data.canvas.getContext('2d');
ctx.fillRect(0, 0, 100, 100);
};
Key points
- Canvas rendering in Worker — off main thread for games, charts, image processing.
- Transfer control from DOM canvas or create offscreen.
- No direct DOM from worker — post bitmap or use WebGL.
- Fallback when unsupported: main thread canvas.