Since March 2023, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
The HTMLCanvasElement.transferControlToOffscreen() method transfers control to an OffscreenCanvas object, either on the main thread or on a worker.
transferControlToOffscreen()
None.
An OffscreenCanvas object.
InvalidStateError DOMException
Throws if:
HTMLCanvasElement.getContext()
The following example shows how to transfer control to an OffscreenCanvas object on the main thread.
const htmlCanvas = document.createElement("canvas");
const offscreen = htmlCanvas.transferControlToOffscreen();
const gl = offscreen.getContext("webgl");
// Some drawing using the gl context…
The following example shows how to transfer control to an OffscreenCanvas object on a worker.
const offscreen = document.querySelector("canvas").transferControlToOffscreen();
const worker = new Worker("my-worker-url.js");
worker.postMessage({ canvas: offscreen }, [offscreen]);
| Specification |
|---|
| HTML> # dom-canvas-transfercontroltooffscreen-dev> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
transferControlToOffscreen |
69 | 79 | 105 | 56 | 16.4 | 69 | 105 | 48 | 16.4 | 10.0 | 69 | 16.4 |
HTMLCanvasElement
OffscreenCanvas
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/transferControlToOffscreen