This post is from a low-reputation account and contains an unverified outbound link. Be cautious before clicking external links.
In the following Github example, init webgl, the clearing, size in html, pixels in canvas.
Init Webgl:
canvas.getContext("webgl2");
Clear:
gl.clearColor(1.0,0.0,0.0,1.0);
this.clear(this.COLOR_BUFFER_BIT | this.DEPTH_BUFFER_BIT);
Size in html:
this.canvas.style.width = width;
this.canvas.style.height = height;
Pixels in Canvas:
this.viewport(0, 0, width, height);
The result is: