A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/getContextAttributes below:

CanvasRenderingContext2D: getContextAttributes() method - Web APIs

This example shows how you can specify context attributes when creating a canvas context, and then call getContextAttributes() to read back the actual parameters that the browser used.

const logElement = document.getElementById("log");
function log(text) {
  logElement.innerText += text;
}

First we create a context using HTMLCanvasElement.getContext(), specifying just one context attribute.

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

If the getContextAttributes() method is supported, we use it to read back the actual attributes used by the browser (including those we explicitly specified):

if (ctx.getContextAttributes) {
  const attributes = ctx.getContextAttributes();
  log(JSON.stringify(attributes));
} else {
  log("CanvasRenderingContext2D.getContextAttributes() is not supported");
}

Depending on the attributes supported by the browser, the log below should display a string that looks something like: {alpha: false, colorSpace: 'srgb', desynchronized: false, willReadFrequently: false}


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4