HTMLCanvasElement.transferControlToOffscreen()

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.

方法 HTMLCanvasElement.transferControlToOffscreen() 将控制转移到一个在主线程或者 web worker 的 OffscreenCanvas 对象上。

语法

js
transferControlToOffscreen()

返回值

一个 OffscreenCanvas 对象。

样例

js
var htmlCanvas = document.createElement("canvas");
var offscreen = htmlCanvas.transferControlToOffscreen();
var gl = offscreen.getContext("webgl");

// ... some drawing using the gl context ...

// Push frames back to the original HTMLCanvasElement
gl.commit();

规范

Specification
HTML Standard
# dom-canvas-transfercontroltooffscreen-dev

浏览器兼容性

BCD tables only load in the browser

参见