OffscreenCanvas: OffscreenCanvas() コンストラクター

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.

注: この機能は Web Worker 内で利用可能です。

OffscreenCanvas() コンストラクターは、新しい OffscreenCanvas オブジェクトを生成します。

構文

js
new OffscreenCanvas(width, height)

引数

width

オフスクリーンキャンパスの横幅を表します。

height

オフスクリーンキャンバスの高さを表します。

この例では OffscreenCanvas() コンストラクターを用いてオフスクリーンキャンバスを新しく生成します。次に、 getContext() メソッドを使用して WebGL コンテキストを初期化します。

js
const offscreen = new OffscreenCanvas(256, 256);
const gl = offscreen.getContext("webgl");

仕様書

Specification
HTML Standard
# dom-offscreencanvas-dev

ブラウザーの互換性

BCD tables only load in the browser

関連情報

  • このコンストラクターは、 OffscreenCanvas インターフェイスに属します。