immersive-web / webxr-polyfill

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

Should not polyfill in non-secure contexts #111

Open lojjic opened 4 years ago

lojjic commented 4 years ago

From the WebXR spec:

partial interface Navigator {
  [SecureContext, SameObject] readonly attribute XR xr;
};

The [SecureContext] bit there says that navigator.xr should only be available on secure pages (basically either https or localhost - more details here). Native implementations like Chrome's will honor this, returning undefined for navigator.xr, which currently causes the full polyfill to be injected on non-secure pages.

In my opinion the polyfill should not inject itself in this case, both to comply with the spirit of the spec and to help developers avoid confusion where their non-secure pages developed with the polyfill "work" but break in the future. Open to discussion of course.

jsantell commented 4 years ago

Some thoughts:

Two ways those could both be achieved:

I think logging a warning to the console about the discrepency is the best way to go at the moment

De-Panther commented 4 years ago

WebVR does work on Oculus Quest on insecure context, but it was confusing when an experience that worked on HTTP, didn't work on HTTPS. So adding a warning that says that the experience is using Polyfill and WebXR isn't working on insecure contexts could help.

blairmacintyre commented 4 years ago

Speaking as someone who was just bitten by this, I would like something to be surfaced. I use ngrok for testing, and Oculus browser defaults to http instead of https if you type in a domain, both of which work with ngrok. I was testing a WebXR app and it was not working, behaving weird, etc., and finally someone suggested this might be the reason (webxr not being exposed because of http, polyfill faking it with webvr).

Issue: the polyfill doesn't necessarily know if WebXR is available IF you were using a secure context. BUT, if could at least print something like "emulating webxr using webvr. This is an insecure http connection, if you browser supports webxr it won't be available over an insecure context, consider trying https."

I would have noticed if there was anything reported to the console.