# WebXR screen mirroring

**URL:** <https://forum.playcanvas.com/t/webxr-screen-mirroring/32909>\
**Category:** Help & Support\
**Tags:** webxr-vr\
**Created:** [September 8, 2023, 2:57pm UTC](https://forum.playcanvas.com/t/webxr-screen-mirroring/32909 "2023-09-08T14:57:38Z")\
**Posts on this page:** 1\
**Showing post:** 19

<div class="post-metadata">

**Author:** ![LucaHeft](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/lucaheft/32/9676_2.png) [@LucaHeft](https://forum.playcanvas.com/u/LucaHeft)\
**Post date:** [September 12, 2023, 9:34am UTC](https://forum.playcanvas.com/t/webxr-screen-mirroring/32909/19 "2023-09-12T09:34:23Z")

</div>

Here is my final script which will mirror the left eye to the html canvas:

```javascript
var ScreenMirroring = pc.createScript('screenMirroring');

ScreenMirroring.prototype.initialize = function () {
    this.app.on('postrender', this.postRender, this);

    this.app.xr.on('start', function () {
        this.isActive = true;
    }, this);
    this.app.xr.on('end', function () {
        this.isActive = false;
    }, this);

    this.isActive = false;
};

ScreenMirroring.prototype.postRender = function () {
    if (this.isActive) {
        let gd = this.app.graphicsDevice;
        let webglLayer = this.app.xr.session.renderState.baseLayer;
        let cs = getComputedStyle(gd.canvas);
        let canvasWidth = parseInt(cs.width);
        let canvasHeight = parseInt(cs.height);
        let aspect = canvasWidth / canvasHeight;
        let croppedHeight = parseInt(gd.width / 2 / aspect);
        let heightOffset = (gd.height - croppedHeight) / 2;

        gd.gl.bindFramebuffer(gd.gl.READ_FRAMEBUFFER, webglLayer.framebuffer);
        gd.gl.bindFramebuffer(gd.gl.DRAW_FRAMEBUFFER, null);
        gd.gl.blitFramebuffer(0, heightOffset, gd.width / 2, gd.height - heightOffset, 0, 0, gd.width, gd.height, gd.gl.COLOR_BUFFER_BIT, gd.gl.NEAREST);
        gd.gl.bindFramebuffer(gd.gl.FRAMEBUFFER, webglLayer.framebuffer);
    }
};

```

**Important:** Anti aliasing needs to be disabled!

---

_[View the full topic](https://forum.playcanvas.com/t/webxr-screen-mirroring/32909)._
