CanvasRenderingContext2D: getContextAttributes() method

The CanvasRenderingContext2D.getContextAttributes() method returns an object that contains the actual context parameters. Context attributes can be requested with HTMLCanvasElement.getContext() on context creation.

Syntax

js

getContextAttributes()

Parameters

None.

Return value

A CanvasRenderingContext2DSettings object that contains the actual context parameters. It has the following members:

alpha Optional

A Boolean indicating if the canvas contains an alpha channel. If false, the backdrop is always opaque, which can speed up drawing of transparent content and images.

colorSpace Optional

Specifies the color space of the rendering context. Possible values are:

desynchronized Optional

A Boolean indicating the user agent reduced the latency by desynchronizing the canvas paint cycle from the event loop.

willReadFrequently Optional

A Boolean indicating whether or not this canvas uses software acceleration (instead of hardware acceleration) to support frequent read-back operations via getImageData().

Examples

Given context attributes were provided on context creation using HTMLCanvasElement.getContext()

js

let canvas = document.createElement("canvas");
let ctx = canvas.getContext("2d", { alpha: false });

the getContextAttributes() method lets you read back actual attributes used by the user agent:

js

ctx.getContextAttributes();
// returns {alpha: false, colorSpace: 'srgb', desynchronized: false, willReadFrequently: false}

Specifications

Specification
HTML Standard
# 2dcontext:dom-context-2d-canvas-getcontextattributes-2

Browser compatibility

BCD tables only load in the browser

See also