Baseline 2023
Newly available
The HTMLCanvasElement.transferControlToOffscreen()
method transfers control to an OffscreenCanvas
object, either on the main thread or on a worker.
transferControlToOffscreen()
Parameters
None.
Return valueAn 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]);
Specifications Browser compatibility See also
HTMLCanvasElement
OffscreenCanvas
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4