OffscreenCanvas: OffscreenCanvas() constructor

Note: This feature is available in Web Workers.

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

Syntax

js
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.

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

Specifications

See also