OffscreenCanvas

interface

interface OffscreenCanvas extends EventTarget

A canvas that can be rendered to off the main thread and without being attached to the DOM. It exposes drawing contexts via OffscreenCanvas.getContext and can produce a Blob or ImageBitmap from its contents.

See also

variable

var OffscreenCanvas: { … }

The constructor object for OffscreenCanvas, used to create a new offscreen canvas with the given width and height that can be rendered to without being attached to the DOM.

See also

Constructors

constructor

new OffscreenCanvas(width: number, height: number): OffscreenCanvas

Properties

height

height: number

The height of the canvas.

width

width: number

The width of the canvas.

prototype

prototype: OffscreenCanvas

Methods

convertToBlob

convertToBlob(options?: ImageEncodeOptions): Promise<Blob>

Create a Blob object representing the image contained in the canvas.

getContext

getContext(contextId: "bitmaprenderer", options?: any): ImageBitmapRenderingContext | null

Get a drawing context for the canvas. If this was previously called, it will return the same context.

getContext(contextId: "webgpu", options?: any): GPUCanvasContext | null
getContext(contextId: OffscreenRenderingContextId, options?: any): OffscreenRenderingContext | null
getContext(contextId: "2d" | "webgl" | "webgl2", options?: any): null

transferToImageBitmap

transferToImageBitmap(): ImageBitmap

Create an ImageBitmap object representing the image contained in the canvas.