Screenshots using WebXR (mobile)


I’m trying to get a screenshot in an app using WebXR.
This is the code I have right now:

var texture = new pc.gfx.Texture(;
var image ='image/png');
    var img = new Image();
    img.onload = function () {
        texture.minFilter = pc.gfx.FILTER_LINEAR;
        texture.magFilter = pc.gfx.FILTER_LINEAR;
        texture.addressU = pc.gfx.ADDRESS_CLAMP_TO_EDGE;
        texture.addressV = pc.gfx.ADDRESS_CLAMP_TO_EDGE;
    img.src = image;
    texture.setSource( img );
    this.photoPanel.element.texture = texture;

So here’s the tricky part. This code works when I’m still not in AR mode, it takes a screenshot and renders into the texture successfully.
However, if I enter XR mode (with the device’s camera) and do the same thing, I only get a black texture.
Is it possible that “Preserve Drawing Buffer” is disabled while in AR mode somehow?

Kind regards

Hi @VitorOliveira and welcome,

Not sure what’s the issue, invoking @moka he most likely will know more about this issue.

When rendering into WebXR, it creates special frame buffer texture, instead of using back buffer.
So you probably want to get texture from that framebuffer and save it, instead of backbuffer (which is what toDataURL provides).