BabylonJS/Babylon.js · error

Persistent anchor enumeration is not supported in this envir

Error message

Persistent anchor enumeration is not supported in this environment/browser

What it means

The persistentAnchors getter enumerates previously persisted anchor handles from the XRSession's persistentAnchors property. That property is part of the optional WebXR persistent anchors extension; when it is undefined (session or browser does not implement it), the getter throws instead of returning an empty list, so callers do not mistake 'unsupported' for 'no persistent anchors'.

Source

Thrown at packages/dev/core/src/XR/features/WebXRAnchorSystem.pure.ts:302

     * Whether the current XR session exposes all session-level persistent anchor APIs
     * @returns Whether all session-level persistent anchor APIs are supported
     */
    public get isPersistentAnchorSupported(): boolean {
        const session = this._xrSessionManager.session;
        return (
            !!session && session.persistentAnchors !== undefined && typeof session.restorePersistentAnchor === "function" && typeof session.deletePersistentAnchor === "function"
        );
    }

    /**
     * Get the persistent anchor handles known to the current XR session
     * @returns The persistent anchor handles
     * @throws If persistent anchor enumeration is not supported by the current session
     */
    public get persistentAnchors(): ReadonlyArray<string> {
        const persistentAnchors = this._xrSessionManager.session?.persistentAnchors;
        if (persistentAnchors === undefined) {
            throw new Error("Persistent anchor enumeration is not supported in this environment/browser");
        }
        return persistentAnchors;
    }

    /**
     * Request a persistent handle for a tracked anchor
     * @param anchor The Babylon anchor to persist
     * @returns A promise that resolves with the persistent handle
     * @throws If requesting persistent handles is not supported by the native anchor
     */
    public async requestPersistentHandleAsync(anchor: IWebXRAnchor): Promise<string> {
        const requestPersistentHandle = anchor.xrAnchor.requestPersistentHandle;
        if (!requestPersistentHandle) {
            throw new Error("Requesting persistent anchor handles is not supported in this environment/browser");
        }
        const handle = await requestPersistentHandle.call(anchor.xrAnchor);
        this._setPersistentHandle(anchor, handle);
        return handle;

View on GitHub (pinned to 0592b347b8)

Solutions

  1. Request the persistent anchors feature in the session's optionalFeatures
  2. Guard the read with typeof session?.persistentAnchors !== 'undefined' before accessing
  3. Treat the throw as 'persistence unavailable' and skip restore logic
  4. Update browser/runtime to one implementing XRSession.persistentAnchors

Example fix

// before
const handles = anchorSystem.persistentAnchors;
// after
const session = xrSessionManager.session;
if (session && 'persistentAnchors' in session) {
  const handles = anchorSystem.persistentAnchors;
} else {
  console.warn('persistent anchors not supported');
}
Defensive patterns

Strategy: type-guard

Validate before calling

const canEnumerate = typeof xrSessionManager.session?.persistentAnchors !== 'undefined';

Type guard

function supportsPersistentEnumeration(session: XRSession | undefined): session is XRSession & { persistentAnchors: ReadonlyArray<string> } {
  return !!session && 'persistentAnchors' in session;
}

Try / catch

try {
  const handles = anchorSystem.persistentAnchors;
} catch {
  console.warn('persistent anchors not supported; skipping restore flow');
}

Prevention

When it happens

Trigger: Reading anchorSystem.persistentAnchors when _xrSessionManager.session.persistentAnchors is undefined — session created without anchors/persistent-anchors support, or browser lacking the persistent anchor API.

Common situations: Devices/browsers implementing anchors but not persistence, missing feature negotiation in optionalFeatures, calling before the session is fully created or after it ended.

Related errors


AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30). Data as JSON: /api/errors/9277cb9f615f92c6. Report an issue: GitHub.