Skip to main content

Function: webStorageAdapter()

function webStorageAdapter(storage, key): PersistAdapter;

Persist to any Storage-shaped thing.

storage may be a thunk, and that is the form the built-in adapters use: merely reading globalThis.localStorage throws SecurityError when storage is blocked (a sandboxed iframe, third-party cookies off), so evaluating it at module scope would blow up on import — before any try/catch here could help. Behind a thunk, every access happens inside one.

Blocked storage, corrupt JSON, a foreign schema, or a full quota all degrade to a silent no-op. Persistence is best-effort; it must never break the store.

Parameters

ParameterType
storage| StorageLike | (() => StorageLike | undefined)
keystring

Returns

PersistAdapter