Dev.Lib
arrow_backBack to Blogs
LEVEL_077.10June 27, 20261 min read

OffscreenCanvas

Web Platform APIs

Canvas rendering in Worker — off main thread for games, charts, image processing.

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.

Further reading

Related concepts