For AI agents: a documentation index is available at /llms.txt. Markdown versions of all pages are available by appending .md to any URL.
Interface OffscreenCanvas
height: number;
oncontextlost: ((this: OffscreenCanvas, ev: Event) => any) | null;
oncontextrestored: ((this: OffscreenCanvas, ev: Event) => any) | null;
width: number;
addEventListener<K extends keyof OffscreenCanvasEventMap>(
type: K,
listener: (this: OffscreenCanvas, ev: OffscreenCanvasEventMap[K]) => any,
options?: boolean | AddEventListenerOptions,
): void;
addEventListener(
type: string,
listener: EventListenerOrEventListenerObject,
options?: boolean | AddEventListenerOptions,
): void;
convertToBlob(options?: ImageEncodeOptions): Promise<Blob>;
dispatchEvent(event: Event): boolean;
getContext(
contextId: "2d",
options?: any,
): OffscreenCanvasRenderingContext2D | null;
getContext(
contextId: "bitmaprenderer",
options?: any,
): ImageBitmapRenderingContext | null;
getContext(contextId: "webgl", options?: any): WebGLRenderingContext | null;
getContext(
contextId: "webgl2",
options?: any,
): WebGL2RenderingContext | null;
getContext(
contextId: OffscreenRenderingContextId,
options?: any,
): OffscreenRenderingContext | null;
removeEventListener<K extends keyof OffscreenCanvasEventMap>(
type: K,
listener: (this: OffscreenCanvas, ev: OffscreenCanvasEventMap[K]) => any,
options?: boolean | EventListenerOptions,
): void;
removeEventListener(
type: string,
listener: EventListenerOrEventListenerObject,
options?: boolean | EventListenerOptions,
): void;
transferToImageBitmap(): ImageBitmap;
}
Hierarchy
- EventTarget
- OffscreenCanvas
Index
Properties
height
The height property returns and sets the height of an OffscreenCanvas object.
oncontextlost
oncontextrestored
width
The width property returns and sets the width of an OffscreenCanvas object.
Methods
addEventListener
-
addEventListener<K extends keyof OffscreenCanvasEventMap>(
type: K,
listener: (this: OffscreenCanvas, ev: OffscreenCanvasEventMap[K]) => any,
options?: boolean | AddEventListenerOptions,
): voidThe
addEventListener()method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.Type Parameters
- K extends keyof OffscreenCanvasEventMap
Parameters
- type: K
- listener: (this: OffscreenCanvas, ev: OffscreenCanvasEventMap[K]) => any
Optionaloptions: boolean | AddEventListenerOptions
Returns void
-
addEventListener(
type: string,
listener: EventListenerOrEventListenerObject,
options?: boolean | AddEventListenerOptions,
): voidThe
addEventListener()method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.Parameters
- type: string
- listener: EventListenerOrEventListenerObject
Optionaloptions: boolean | AddEventListenerOptions
Returns void
convertToBlob
-
The
OffscreenCanvas.convertToBlob()method creates a Blob object representing the image contained in the canvas.Parameters
Optionaloptions: ImageEncodeOptions
Returns Promise<Blob>
dispatchEvent
-
The
dispatchEvent()method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order. The normal event processing rules (including the capturing and optional bubbling phase) also apply to events dispatched manually with dispatchEvent().Parameters
- event: Event
Returns boolean
getContext
-
The
OffscreenCanvas.getContext()method returns a drawing context for an offscreen canvas, or null if the context identifier is not supported, or the offscreen canvas has already been set to a different context mode.Parameters
- contextId: "2d"
Optionaloptions: any
Returns OffscreenCanvasRenderingContext2D | null
-
Parameters
- contextId: "bitmaprenderer"
Optionaloptions: any
Returns ImageBitmapRenderingContext | null
-
Parameters
- contextId: "webgl"
Optionaloptions: any
Returns WebGLRenderingContext | null
-
Parameters
- contextId: "webgl2"
Optionaloptions: any
Returns WebGL2RenderingContext | null
-
getContext(
contextId: OffscreenRenderingContextId,
options?: any,
): OffscreenRenderingContext | nullParameters
- contextId: OffscreenRenderingContextId
Optionaloptions: any
Returns OffscreenRenderingContext | null
removeEventListener
-
removeEventListener<K extends keyof OffscreenCanvasEventMap>(
type: K,
listener: (this: OffscreenCanvas, ev: OffscreenCanvasEventMap[K]) => any,
options?: boolean | EventListenerOptions,
): voidThe
removeEventListener()method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target. The event listener to be removed is identified using a combination of the event type, the event listener function itself, and various optional options that may affect the matching process; see Matching event listeners for removal.Type Parameters
- K extends keyof OffscreenCanvasEventMap
Parameters
- type: K
- listener: (this: OffscreenCanvas, ev: OffscreenCanvasEventMap[K]) => any
Optionaloptions: boolean | EventListenerOptions
Returns void
-
removeEventListener(
type: string,
listener: EventListenerOrEventListenerObject,
options?: boolean | EventListenerOptions,
): voidThe
removeEventListener()method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target. The event listener to be removed is identified using a combination of the event type, the event listener function itself, and various optional options that may affect the matching process; see Matching event listeners for removal.Parameters
- type: string
- listener: EventListenerOrEventListenerObject
Optionaloptions: boolean | EventListenerOptions
Returns void
transferToImageBitmap
-
The
OffscreenCanvas.transferToImageBitmap()method creates an ImageBitmap object from the most recently rendered image of the OffscreenCanvas. The OffscreenCanvas allocates a new image for its subsequent rendering.Returns ImageBitmap
When using the
MDN Reference