All Collections
Advanced Customization
Does Upscope support WebGL
Does Upscope support WebGL
Learn how to make Upscope support WebGL graphics.
Joe avatar
Written by Joe
Updated over a week ago

The way WebGL is implemented in most browsers prevents Upscope from grabbing the content of the canvas. You can make a few changes to your code to allow Upscope to work with WebGL.

Option 1: Change your code

Somewhere in your code, you'll be grabbing the webGL context by doing:

canvas.getContext('webgl')

This needs to be changed into this:

canvas.getContext('webgl', { preserveDrawingBuffer: true })

Option 2: Monkey-patching the code

If you don't want to edit your code, or don't know how to; or simply want to test that this approach works before making changes, you can add the following code right below the Upscope installation code to automatically apply the above change everywhere:

<script>
  HTMLCanvasElement.prototype.__getContext = HTMLCanvasElement.prototype.getContext;
  HTMLCanvasElement.prototype.getContext = function(t, ...args) {
    if(t === 'webgl') return this.__getContext('webgl', { preserveDrawingBuffer: true });
    return this.__getContext(t, ...args);
  }
</script>

Did this answer your question?