Skip to content

fix(wasm): tolerate blocked browser storage - #2213

Merged
chaliy merged 1 commit into
mainfrom
2026-07-26-fix-browser-example-crash-with-blocked-localstorage
Jul 27, 2026
Merged

fix(wasm): tolerate blocked browser storage#2213
chaliy merged 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 4489f25 Commit Preview URL Jul 27 2026, 09:18 AM

@chaliy
chaliy force-pushed the 2026-07-26-fix-browser-example-crash-with-blocked-localstorage branch from ef65552 to 4489f25 Compare July 27, 2026 09:17
@chaliy
chaliy merged commit 8bc3f71 into main Jul 27, 2026
19 checks passed
@chaliy
chaliy deleted the 2026-07-26-fix-browser-example-crash-with-blocked-localstorage branch July 27, 2026 09:31
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