Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion src/framework/xr/xr-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,14 +317,37 @@ class XrManager extends EventHandler {
// 2. Space class
// 3. Controllers class

if (this._supported) {
if (this._supported && XrManager._allowsSpatialTracking()) {
navigator.xr.addEventListener('devicechange', () => {
this._deviceAvailabilityCheck();
});
this._deviceAvailabilityCheck();
}
}

/**
* The startup availability probe calls {@link navigator.xr.isSessionSupported}, which the
* browser blocks - logging a `xr-spatial-tracking is not allowed in this document` permissions
* policy violation - when the `xr-spatial-tracking` feature is disallowed for the document (for
* example when the app runs in an iframe without `allow="xr-spatial-tracking"`). Only skip the
* probe when the policy explicitly disallows the feature; when the Feature Policy API is
* unavailable (e.g. Safari / visionOS) we cannot tell, so proceed as before.
*
* @returns {boolean} - True if the probe should run.
* @private
*/
static _allowsSpatialTracking() {
const featurePolicy = platform.browser && document.featurePolicy;
if (featurePolicy?.allowsFeature) {
const allowed = featurePolicy.allowsFeature('xr-spatial-tracking');
if (!allowed) {
Debug.warn('WebXR availability detection skipped: the "xr-spatial-tracking" feature is disallowed for this document. If XR is needed, add allow="xr-spatial-tracking" to the embedding iframe or send a matching Permissions-Policy header.');
}
return allowed;
}
return true;
}

/**
* Tests whether an immersive WebXR session of the given type can run on the specified graphics
* backend. Unlike {@link XrManager#isAvailable}, this is a static method that can be called
Expand Down