MozillaReality / webxr-ios-js

INACTIVE - A JS implementation of WebXR used *only* in Mozilla's WebXR Viewer
Mozilla Public License 2.0
71 stars 30 forks source link

Three.js WebXR AR examples don't recognize our WebXR API #80

Closed takahirox closed 1 week ago

takahirox commented 4 years ago

Three.js WebXR AR examples don't recognize our AR capability. When the application starts up Three.js ARButton checks navigator.xr but at that time it seems navigator.xr isn't defined yet.

Android Chrome (native WebXR API) and WebXR Emulator Extension work fine. So maybe there is something problem in our side.

blairmacintyre commented 4 years ago

are we not definitely navigator.xr in the shim? Didn't something change to navigator.XR or something? (fuzzy memory here)

takahirox commented 4 years ago

I need to investigate but I guess WebXR API detection with navigator.xr is somehow done before loading shim. When is shim exactly loaded?

blairmacintyre commented 4 years ago

That's not possible or shouldn't be. The shim is loaded using the WkWebView feature that preloads some JS before loading the page. Are you sure the shim that's bundled with xcode is actually setting .xr and not something else like .XR?

takahirox commented 4 years ago

Yes, navigator.xr.

I'll investigate closer today.

takahirox commented 4 years ago

I found an interesting fact.

  1. https://threejs.org/examples/#webxr_ar_paint
  2. https://threejs.org/examples/webxr_ar_paint.html

They are the same Three.js AR paint example. Our WebXR API is recognized in 2. while it isn't in 1.

The difference is whether using <iframe>. 2. is the WebXR AP paint example itself and 1. opens 2. in <iframe>.

I set break point in the example in 1 and realized that navigator.xr seems to be never defined in <iframe>.

So my speculation is the shim has no effect to a page loaded in <iframe>. Can this likely happen from the view of preloading with WkWebView?

blairmacintyre commented 4 years ago

Yes, that could definitely be the case.

Is webxr supposed to work in iFrames? A subset of it? Seems dangerous.

joshmarinacci commented 4 years ago

I seem to recall us discussing webxr in iframes about a year ago. I think we agreed to have some property set on the iframe to enable it.

takahirox commented 4 years ago

From Three.js html code

<iframe id="viewer" name="viewer" allowfullscreen allowvr onmousewheel="">

It has allowvr (not "xr" tho), is this what @joshmarinacci pointed out?

takahirox commented 4 years ago

And, I'm not familiar with WebKit at all. Is it technically possible to preload the shim even in <iframe>?

blairmacintyre commented 4 years ago

It has allowvr (not "xr" tho), is this what @joshmarinacci pointed out?

Probably.

And, I'm not familiar with WebKit at all. Is it technically possible to preload the shim even in