Kitware / itk-vtk-viewer

2D / 3D web image, mesh, and point set viewer using itk-wasm and vtk.js
https://kitware.github.io/itk-vtk-viewer/
BSD 3-Clause "New" or "Revised" License
210 stars 64 forks source link

Access to the feature "xr" is disallowed by permissions policy. #534

Open oeway opened 2 years ago

oeway commented 2 years ago

When running the viewer in a sandboxed iframe it triggers error from the following code:

if (
      navigator.xr !== undefined &&
      navigator.xr.isSessionSupported('immersive-vr')
    ) {
      publicAPI.invokeHaveVRDisplay();
    }

The error is:

Uncaught (in promise) DOMException: Failed to execute 'isSessionSupported' on 'XRSystem': Access to the feature "xr" is disallowed by permissions policy.
    at QO.e.get3DContext (https://kitware.github.io/itk-vtk-viewer/app/itkVtkViewer.js:2:1685856)
    at QO.e.initialize (https://kitware.github.io/itk-vtk-viewer/app/itkVtkViewer.js:2:1684512)
    at QO.e.buildPass (https://kitware.github.io/itk-vtk-viewer/app/itkVtkViewer.js:2:1684380)
    at e.apply (https://kitware.github.io/itk-vtk-viewer/app/itkVtkViewer.js:2:1593961)
    at e.traverse (https://kitware.github.io/itk-vtk-viewer/app/itkVtkViewer.js:2:1593820)
    at R_.e.traverse (https://kitware.github.io/itk-vtk-viewer/app/itkVtkViewer.js:2:1656922)
    at QO.e.traverseAllPasses (https://kitware.github.io/itk-vtk-viewer/app/itkVtkViewer.js:2:1701435)
    at u (https://kitware.github.io/itk-vtk-viewer/app/itkVtkViewer.js:2:1561585)
    at e.render (https://kitware.github.io/itk-vtk-viewer/app/itkVtkViewer.js:2:1570889)
    at e.initialize (https://kitware.github.io/itk-vtk-viewer/app/itkVtkViewer.js:2:1562143)

I think we need to add a try catch statement to prevent this error.

You can reproduce it with this: https://jupyter.imjoy.io/lab/index.html?load=https://gist.github.com/oeway/391b4352ea57b5682366ce3dc2fa9174&open=1