Skip to content

fix(wasm): tolerate blocked browser storage#2213

Open
chaliy wants to merge 1 commit into
mainfrom
2026-07-26-fix-browser-example-crash-with-blocked-localstorage
Open

fix(wasm): tolerate blocked browser storage#2213
chaliy wants to merge 1 commit into
mainfrom
2026-07-26-fix-browser-example-crash-with-blocked-localstorage

Conversation

@chaliy

@chaliy chaliy commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Motivation

  • The browser persistence adapter read globalThis.localStorage as a default parameter, which can throw a SecurityError in sandboxed/opaque-origin/storage-blocked contexts and abort shell initialization.

Description

  • Move storage resolution out of the parameter list and into a guarded initialization that catches thrown errors when reading globalThis.localStorage and treats storage as unavailable in that case.
  • Accept an explicit storage (configuredStorage) parameter while preserving existing behavior when callers pass a valid Storage instance.
  • Make save() and clear() tolerant of unavailable storage by having save() return false on write errors and wrapping clear() in a try/catch so failures do not throw.
  • Add a regression test that installs a throwing globalThis.localStorage getter and verifies load() returns defaults, save() reports false, and clear() does not throw.

Testing

  • Ran node --test examples/browser/browser-local.test.js and observed all tests pass (8 passed).
  • Installed example deps and ran the browser example build (npm install then npm run build in examples/browser), and the vite build completed successfully.

Codex Task

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 26, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
bashkit ef65552 Commit Preview URL Jul 26 2026, 10:45 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant