[whatwg] [canvas] Proposal for supportsContext

Tobie Langel tobie.langel at gmail.com
Mon Sep 10 12:28:50 PDT 2012


On Sep 10, 2012, at 8:14 PM, Dean Jackson <dino at apple.com> wrote:

> I propose adding a new method to HTMLCanvasElement:
>
> interface HTMLCanvasElement : HTMLElement {
>  boolean supportsContext(DOMString contextId, any... arguments);
> };
>
> supportsContext takes the same parameters as getContext, and simply returns
> true if the corresponding call to getContext would have returned a valid
> context, false otherwise.

What about enabling feature detection by providing a method per context?

interface HTMLCanvasElement : HTMLElement {
  object get2DContext();
  object getWebGLContext(any... args);
};

That way, developers can use idiomatic JS for feature testing like
pretty much everywhere else on the Web platform:

if (canvas.get2DContext) {
  // do stuff with 2D canvas
}

--tobie



More information about the whatwg mailing list