canvaskit-wasm 0.39 build 2026-04-29

WebGLOptions

Plain JS object passed to CK.GetWebGLContext and CK.MakeWebGLContext. Mirrors the WebGL getContext attribute object, but typed as numbers (CanvasKit converts them at the C++ boundary). All fields are optional; sensible defaults are picked when omitted.

const glHandle = CK.GetWebGLContext(canvasEl, {
  alpha: 1,
  antialias: 1,
  depth: 1,
  majorVersion: 2,
  preserveDrawingBuffer: 0,
});
const grContext = CK.MakeGrContext(glHandle);

You usually only need majorVersion: 2 (force WebGL 2) and preserveDrawingBuffer: 1 (if you need to read back). Everything else is fine at default.

Fields

FieldTypeNotes
alphanumber1 to keep canvas alpha; 0 for fully opaque.
antialiasnumber1 to enable hardware MSAA on the default framebuffer.
depthnumber1 to allocate a depth buffer.
enableExtensionsByDefaultnumber1 to opt into all available WebGL extensions Skia knows about.
explicitSwapControlnumberEmscripten-specific: 1 to opt out of the auto-swap on rAF.
failIfMajorPerformanceCaveatnumber1 to refuse a software fallback context.
majorVersionnumber1 or 2 — pick the WebGL major version. Default 2 if available.
minorVersionnumberWebGL minor version (rarely set).
preferLowPowerToHighPerformancenumber1 to bias toward integrated GPU.
premultipliedAlphanumber1 if the canvas's backbuffer should be premultiplied.
preserveDrawingBuffernumber1 to retain the framebuffer between frames (needed for readPixels after rAF).
renderViaOffscreenBackBuffernumber1 to render into an offscreen FBO and blit on swap.
stencilnumber1 to allocate a stencil buffer.

See also