immersive-web / webxr-polyfill

Use the WebXR Device API today, providing fallbacks to native WebVR 1.1 and Cardboard
Apache License 2.0
378 stars 84 forks source link

requestSession fails on iPad OS 13 #140

Open WoodNeck opened 4 years ago

WoodNeck commented 4 years ago

Hello again, I found another issue. If fullscreen API is supported in iOS devices, like iPad OS 13+ safari, requestSession will be rejected with the error "Unable to present"; Here's my explanation:

in iPad OS 13+, navigator.platform has following values.

which makes isIOS() returns true only for the mobile mode.

The problem is, polyfill creates a new canvas element when requestSession is called, like the following code, and uses it as a layer source for VRDisplay's requestPresent method. image

VRDisplay's wrapForFullscreen is the only place where it wraps the canvas element with wrapper element and appends it to the body, but it won't if it's iOS environment. image

So, it will call requestFullscreen for canvas before it is added to the document, so a fullscreen error will be triggered and requestSession will be rejected also.

One suggestion is least guaranteeing that the canvas is in the document when it's created.

I know there's no meaning in supporting iPad right now, but I guess when Fullscreen API lands on iOS someday it will be meaningful to do it.

Sorry for not preparing any demos. I think this issue can be reproduced in https://naver.github.io/egjs-view360/panoviewer.html, until I release another version of it.

Thanks!