CanvasRenderingContext2D.getContextAttributes()

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

ctx.getContextAttributes();

Return value

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

alpha

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.

desynchronized

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

Examples

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

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:

ctx.getContextAttributes();
// returns {alpha: false, desynchronized: false}

Specifications

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

Browser compatibility

BCD tables only load in the browser

See also