W3cubDocs

/Web APIs

HTMLCanvasElement: transferControlToOffscreen() method

Baseline 2023
Newly available

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.

Syntax

transferControlToOffscreen()

Parameters

None.

Return value

An OffscreenCanvas object.

Exceptions

InvalidStateError DOMException

Throws if:

Examples

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]);

Specifications

Browser compatibility

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

See also

© 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