files/en-us/web/api/htmlcanvaselement/transfercontroltooffscreen/index.md
{{APIRef("Canvas API")}}
The HTMLCanvasElement.transferControlToOffscreen() method transfers control to an {{domxref("OffscreenCanvas")}} object, either on the main thread or on a worker.
transferControlToOffscreen()
None.
An {{domxref("OffscreenCanvas")}} object.
InvalidStateError {{domxref("DOMException")}}
The following example shows how to transfer control to an {{domxref("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 {{domxref("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}}
{{Compat}}