Skip to content

fix(figma): guard localStorage access in the srcdoc sandbox - #22

Merged
DavidBabinec merged 1 commit into
mainfrom
fix/figma-localstorage-securityerror
Aug 27, 2026
Merged

fix(figma): guard localStorage access in the srcdoc sandbox#22
DavidBabinec merged 1 commit into
mainfrom
fix/figma-localstorage-securityerror

Conversation

@DavidBabinec

Copy link
Copy Markdown
Contributor

Fixes #11

The bug

Saving from the Figma plugin did nothing and logged SecurityError: Failed to read the 'localStorage' property from 'Window'. The plugin runs the bundled editor inside Figma's sandboxed about:srcdoc frame, where reading localStorage is denied.

The fix

The save path's rate limiter read localStorage on every push and threw before the save ran, so the click was lost. All three www localStorage touch points now go through a safeLocalStorage wrapper that falls back to an in-memory store when the browser blocks access. On the web nothing changes. Scoped to the www editor that Figma bundles; the separate wp save path is not sandboxed and is untouched.

Verification

bun run test:www     # 152 pass, 0 fail (5 new)
bun run build:www    # clean
bun run build:figma  # clean

A new test denies localStorage the way the sandbox does. It fails without the fix and passes with it.

The bundled editor runs inside Figma's about:srcdoc frame, where reading
window.localStorage throws SecurityError. The save rate limiter read it on
every push and threw before the save ran, so clicking Save did nothing.
Access now falls back to an in-memory store when the browser blocks it.
@DavidBabinec
DavidBabinec merged commit 5cd208f into main Aug 27, 2026
6 checks passed
@DavidBabinec
DavidBabinec deleted the fix/figma-localstorage-securityerror branch August 27, 2026 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Figma Plugin: It is not possible to progress.

1 participant