OffscreenCanvas: OffscreenCanvas() constructor

The OffscreenCanvas() constructor returns a newly instantiated OffscreenCanvas object.

Syntax

new OffscreenCanvas(width, height)

Parameters

width

The width of the offscreen canvas.

height

The height of the offscreen canvas.

Examples

This example creates a new offscreen canvas using the OffscreenCanvas() constructor. We then initialize a WebGL context on it using the getContext() method.

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

Specifications

Specification
HTML Standard
# dom-offscreencanvas-dev

Browser compatibility

BCD tables only load in the browser

See also