HTMLCanvasElement: transferControlToOffscreen() method
Baseline 2023Newly 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
js
transferControlToOffscreen()
Parameters
None.
Return value
An OffscreenCanvas
object.
Exceptions
InvalidStateError
DOMException
-
Throws if:
- the canvas has been set a context mode by calling
HTMLCanvasElement.getContext()
- the canvas has transferred its control to offscreen by calling
HTMLCanvasElement.transferControlToOffscreen()
.
- the canvas has been set a context mode by calling
Examples
The following example shows how to transfer control to an OffscreenCanvas
object on the main thread.
js
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.
js
const offscreen = document.querySelector("canvas").transferControlToOffscreen();
const worker = new Worker("my-worker-url.js");
worker.postMessage({ canvas: offscreen }, [offscreen]);
Specifications
Specification |
---|
HTML # dom-canvas-transfercontroltooffscreen-dev |
Browser compatibility
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
transferControlToOffscreen |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
See also
- The interface defining this method,
HTMLCanvasElement
OffscreenCanvas