posthog-js icon indicating copy to clipboard operation
posthog-js copied to clipboard

No Support for environments where `localStorage` & `cookies` are not supported.

Open Wolverin-e opened this issue 2 months ago • 1 comments

Bug description

Hi PostHog Team, You are building an awesome & very useful project. I am using for 1-2 Months & I have to say everything is well designed & working good. I am currently bumping the posthog-js library version to 1.280.1 & I am facing some storage related errors. [PostHog.js] localStorage error: SecurityError: Failed to read the 'localStorage' property from 'Window': Storage is disabled inside 'data:' URLs..

How to reproduce

  1. Load the library dynamically in a figma plugin, where the UI is loaded using 'data:' URIs.
  2. Chrome disables cookies & localStorage when UI is loaded using the 'data:' URIs.
  3. So when capture calls are made, they call has_opted_out_capturing which then accesses either cookies or localStorage, which creates console errors [PostHog.js] localStorage error: SecurityError: Failed to read the 'localStorage' property from 'Window': Storage is disabled inside 'data:' URLs..

Related sub-libraries

  • [ ] All of them
  • [X] posthog-js (web)
  • [ ] posthog-js-lite (web lite)
  • [ ] posthog-node
  • [ ] posthog-react-native
  • [ ] @posthog/react
  • [ ] @posthog/ai
  • [ ] @posthog/nextjs-config

Additional context

  1. Figma Plugins load the UI HTML bundle like a data URI.

Possible solutions:

  1. Add support for memory type to opt_out_capturing_persistence_type just like persistence config.
  2. Add support for customStorage in config & use it for all storage needs.

Thank you for your bug report – we love squashing them!

Wolverin-e avatar Oct 25 '25 10:10 Wolverin-e