demo · v136

OffscreenCanvas in worker

The actual motivation from the chromestatus entry: an OffscreenCanvas transferred to a worker has no DOM, so it cannot pick up the page's lang attribute. v136 lets the worker set ctx.lang on the offscreen context, restoring locale-correct font selection.

Renders the same Han character in four locales on a worker-side OffscreenCanvas.

worker offscreen.lang = "ja"

worker offscreen.lang = "ko"

worker offscreen.lang = "zh-Hans"

worker offscreen.lang = "zh-Hant"

Pre-136 the worker had no language signal; all four panels used a fallback locale. With ctx.lang, each panel picks the locale-specific glyph.

the code

// main thread
const off = canvas.transferControlToOffscreen();
worker.postMessage({ canvas: off, lang: "ja", ch: "直" }, [off]);

// worker
self.onmessage = (e) => {
  const ctx = e.data.canvas.getContext("2d");
  ctx.lang = e.data.lang;   // 136+
  ctx.font = "120px serif";
  ctx.fillText(e.data.ch, 20, 130);
};

why this angle

The sibling concept covers main-thread canvas where the host element's lang attribute already worked. This concept is the OffscreenCanvas-in-worker case the spec PR explicitly called out: workers have no DOM, so the only way to provide a language signal is through ctx.lang.

see also