posthog-js
posthog-js copied to clipboard
No Support for environments where `localStorage` & `cookies` are not supported.
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
- Load the library dynamically in a figma plugin, where the UI is loaded using 'data:' URIs.
- Chrome disables
cookies&localStoragewhen UI is loaded using the 'data:' URIs. - So when
capturecalls are made, they callhas_opted_out_capturingwhich then accesses eithercookiesorlocalStorage, 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
- Figma Plugins load the UI HTML bundle like a data URI.
Possible solutions:
- Add support for
memorytype toopt_out_capturing_persistence_typejust likepersistenceconfig. - Add support for customStorage in config & use it for all storage needs.