demo · v134

Worker context settings — request vs. actual

The bug that drove this change: a worker requests a context with alpha: false, willReadFrequently: true — but the engine may grant a different combination, and the worker had no way to discover what it actually got. With getContextAttributes() on OffscreenCanvasRenderingContext2D, the worker can finally ask. Pick attributes, transfer to a worker, and watch the round-trip.

probing OffscreenCanvas + getContextAttributes…

Request settings, then ask the worker what it got

attributerequestedworker.getContextAttributes() returnedmatch?
(spawn worker to populate)

The code (worker side)

self.onmessage = ({ data }) => {
  const { canvas, requested } = data;
  const ctx = canvas.getContext('2d', requested);
  self.postMessage({ actual: ctx.getContextAttributes() });
};

see also