Repository navigation
Description
What happened?
Three places read the localStorage global behind a typeof guard:
function browserStorage(): ContextStorage | undefined {
if (typeof localStorage === "undefined") return
return localStorage
}localStorage is an accessor property on the global object, so both typeof localStorage and localStorage perform a [[Get]] that invokes the getter. A
typeof guard therefore runs the very same access and cannot protect the read.
When storage is blocked — a sandboxed frame without allow-same-origin, a denied
origin, dom.storage.enabled=false — that access throws SecurityError and
there is no try here.
The consequence is a blank app rather than a degraded one, because two of these
run at module scope:
atlas/store/ui.ts—const state = createContextState(), exported as
uiStoreand used by the global keys, the panes and the toolbarartifacts/context.ts—export const artifactContext = createArtifactState()atlas/store/sessionTabs.ts— reached during the session page's render
So the throw happens while evaluating the argument, before restore(storage)
(which handles undefined perfectly well) ever runs, and the import fails.
FdaBanner has the mirror-image asymmetry: its write is guarded
try {
localStorage.setItem(DISMISS_KEY, "1")
} catch {}but the read nine lines above, in the createSignal initializer, is not — so the
home page throws while rendering the chip.
This is a known class here, and the rest of the workspace already does it
correctly: pages/session-trace.ts wraps the global in try/catch, and
atlas/files/last-source.ts carries the note "reading globalThis.localStorage is
itself what throws in a sandboxed frame". atlas/files/artifact-boundaries.test.ts
already asserts a component "survives a localStorage getter that throws during
render". These three copies and the FdaBanner read were simply missed.
Steps to reproduce
- Open the workspace in a sandboxed frame (an iframe without
allow-same-origin), or withdom.storage.enabled=false. - Load the app.
- The import of the workspace store throws
SecurityErrorand nothing renders.
The three regressions in atlas/store/blocked-storage.test.ts install a throwing
localStorage getter and fail on 3e94875c with exactly that error.
How did you install OpenScience?
From source (bun dev); also affects the packaged app and the desktop shell.
OpenScience version
Source commit 3e94875c.
Provider and model
Not applicable; the workspace never reaches a model call.
Operating system
Not OS-specific. It depends on the embedding context rather than the platform.
Activity