Closed bug report

Support wiki sandbox storage and environment loading with explicit readiness hints

John Lauer · ·closed by Colby Knox

The registered wiki component widget runs with an opaque origin and CSP connect-src 'self' data:, img-src data: https:. The canonical Babylon9 viewer initialization assumes capabilities not available there.

Observed in an isolated Chromium harness using the actual wiki response CSP and the canonical installed bundle:

  • Camera initialization threw SecurityError when accessing localStorage. The widget now supplies ephemeral document-local storage only when the real storage accessor throws; persistent storage is untouched when available.
  • SceneBuilder's default environment creates a blob URL for its embedded .env texture. The widget CSP does not permit blob fetches. It also creates a default skybox using an external DDS. A screenshot initially retained the Loading overlay. Later rendering showed the chip over a black background. Model-loaded and resource-disposal counters alone did not establish a correctly painted preview.

The widget's private GLB transport is handled separately: component-owned, authenticated iframe navigation transfers verified bytes to the widget, which passes Uint8Array directly to Babylon. No sandbox or wiki visibility policy was relaxed.

Requested shared-viewer support:

  1. Optional injected environment bytes / texture and skybox texture, without requiring a blob URL or external fetch. Preserve the canonical studio lighting when running under the wiki CSP.
  2. Safe ephemeral preference storage when browser storage is denied.
  3. An explicit ready/error result including environment loading, camera readiness and loading-overlay state. Report actionable AI hints instead of leaving consumers to interpret scene counters.
  4. A bounded integration test in an opaque iframe under the actual wiki CSP, requiring a rendered chip and visible loading-overlay dismissal, then repeated destroy/recreate checks.

Source inspected: canonical adom-3d-viewer-babylon9 distribution, chunk-IERganv1.js (SceneBuilder.init and Viewer initialization). This report is about sandbox integration, not a request to weaken the wiki sandbox. Public wiki bundle revision may differ and requires the same check.

2 Replies

Colby Knox ·

All four requests are in adom-3d-viewer 0.7.0, John, and the wiki serves that build on prod now (tag 8dd91ae, 18:08 UTC, bundle 20260910a on the /static/vendor/ route, so the widget's lazy import picks it up).

Root causes, confirmed in the source and in headless Chrome under the wiki's exact widget CSP in an opaque-origin iframe:

  • The bundled studio .env was turned into a blob URL and fetched (connect-src has no blob:), and Babylon then uploads each .env mip level through an <img src="blob:..."> (img-src has no blob:). The blocked environment left every PBR material waiting, which is the black background you saw behind the chip. There is no external DDS in this fork since 0.4.x; the background is a screen-space gradient drawn from a DynamicTexture. If your chunk-IERganv1 build showed a DDS skybox, it predates that; the wiki's vendored bundle and the installable asset are the same 0.7.0 build now.
  • localStorage in the camera setup was already guarded, but the retained overlay was real: a throw in the load path skipped hideLoadingUI, so "Loading..." stayed over a live scene with no error anywhere.

What ships:

  1. Environment from memory: the studio map loads through Babylon's buffer option (no blob URL, no fetch), and images (environment levels, GLB-embedded textures) decode as ImageBitmaps, so no blob: URL is created at all. environmentBytes injects your own .env bytes the same way; environment: "none" skips the map. Canonical studio lighting is preserved under the wiki CSP.
  2. Safe preference storage: a prefs module falls back to document-local memory when storage access throws; the report says storage: "ephemeral".
  3. Explicit readiness: await viewer.whenReady() (also onReady, getReadyReport()) returns { ok, engine: { webglVersion, contextLost }, environment: { source, ready, error }, camera: { ready, mode }, storage, loadingOverlay: "hidden" | "visible", model: { requested, loaded, meshes, vertices, error }, cspViolations: [{ directive, blocked }], hints: [{ code, level, message, action }], version }. ok is true only when the scene rendered, the overlay is gone, the environment is ready or deliberately absent, no CSP violation was recorded and any requested model loaded with geometry. Hints: CSP_BLOCKED (with the directive and blocked URI), MODEL_LOAD_FAILED, MODEL_EMPTY, ENVIRONMENT_FAILED, ENVIRONMENT_PENDING, STORAGE_EPHEMERAL (info), LOADING_OVERLAY_STUCK, WEBGL_CONTEXT_LOST. The overlay now comes down in a finally block whatever the model does. Also new: loadModelBytes(bytes, { extension }) for your verified-bytes transport, so the frame's CSP never sees a model URL; the report reflects it (every call after ready rebuilds from current state).
  4. Bounded integration test: npm run test:sandbox (test/wiki-sandbox.test.mjs) starts an https server carrying the wiki CSP (read live from the git-wiki checkout when present, literal otherwise), frames the harness with sandbox="allow-scripts", and asserts: localStorage really throws, bundle loads, report.ok, environment ready from bundled bytes with zero securitypolicyviolation events, overlay dismissed, model loaded (24 vertices), chip pixels painted in the canvas centre, then three destroy/recreate rounds alternating URL and bytes transport. 32/32 green in headless Chrome (SwiftShader), capped at 120 s.

One host-side fact the test also surfaced: an opaque origin fetches module scripts in CORS mode, so the bundle must be served with Access-Control-Allow-Origin; the wiki's /static/vendor/ route does, a private harness has to as well.

Package: adom/adom-3d-viewer 0.7.0 (latest), bundle asset adom-3d-viewer-babylon9-0.7.0.tar.gz (sha256 24a93739...), source on the page repo and the GitHub mirror. Yours to close once your widget's harness agrees.

Colby Knox ·

Closing against 0.7.0 (all four asks shipped Sep 10, on prod since tag 8dd91ae; 0.7.1 and 0.7.2 since). John, reopen if the sandboxed-frame path misbehaves on a page you can name.

Colby Knox closed this ·

Log in to reply.