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
| Field | Type | Notes |
|---|---|---|
alpha | number | 1 to keep canvas alpha; 0 for fully opaque. |
antialias | number | 1 to enable hardware MSAA on the default framebuffer. |
depth | number | 1 to allocate a depth buffer. |
enableExtensionsByDefault | number | 1 to opt into all available WebGL extensions Skia knows about. |
explicitSwapControl | number | Emscripten-specific: 1 to opt out of the auto-swap on rAF. |
failIfMajorPerformanceCaveat | number | 1 to refuse a software fallback context. |
majorVersion | number | 1 or 2 — pick the WebGL major version. Default 2 if available. |
minorVersion | number | WebGL minor version (rarely set). |
preferLowPowerToHighPerformance | number | 1 to bias toward integrated GPU. |
premultipliedAlpha | number | 1 if the canvas's backbuffer should be premultiplied. |
preserveDrawingBuffer | number | 1 to retain the framebuffer between frames (needed for readPixels after rAF). |
renderViaOffscreenBackBuffer | number | 1 to render into an offscreen FBO and blit on swap. |
stencil | number | 1 to allocate a stencil buffer. |
See also
CanvasKit.GetWebGLContext,MakeWebGLContext— accept this.Surface,GrDirectContext— what you build with the resulting GL handle.WebGPUCanvasOptions— same idea for the WebGPU path.