Skip to content

gl.canvas is undefined: "Uncaught TypeError: Cannot read properties of undefined (reading 'width')" when accessing gl.canvas.width #408

@EndlessJour9527

Description

@EndlessJour9527

Summary

When running code that accesses gl.canvas.width in JSAR Runtime (using either WebGLRenderingContext or WebGL2RenderingContext), the engine throws:

Uncaught TypeError: Cannot read properties of undefined (reading 'width')

Root Cause

gl.canvas is always undefined, unlike in standard browser environments (Chromium, Gecko), where it references the HTMLCanvasElement used to create the context.

Expected Behavior

According to the WebGL specification, gl.canvas MUST point to the source canvas element (or object) for the context. Libraries (e.g., Three.js, Babylon.js) and many user apps depend on this for sizing and rendering logic.

Minimal Reproducible Case

console.log(gl.canvas.width); // should not error, should return a number

References (for standard conformance)

Fix Proposal

Implement the canvas property and ensure it references the appropriate HTMLCanvasElement or OffscreenCanvas instance. Update WebGL context construction and exposure so gl.canvas is correctly populated and reflects the expected APIs per spec.


This issue blocks proper deployment of standard libraries (Three.js, Babylon.js, etc.) and typical WebGL applications on JSAR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions