Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling localStorage Access Restrictions in Iframe for Amplitude #651

Open
batuhan-kajabi opened this issue Jan 25, 2024 · 0 comments
Open
Labels
bug Something isn't working

Comments

@batuhan-kajabi
Copy link

Expected Behavior

The Amplitude JavaScript SDK should handle environments where localStorage access is restricted (such as within certain iframes) without causing uncaught exceptions or crashes in the application.

Current Behavior

When the Amplitude SDK is used in an environment where localStorage is restricted (like in a cross-origin iframe), it attempts to access localStorage and triggers a SecurityError. This issue causes the application to crash or behave unexpectedly due to unhandled exceptions.
Error path: node_modules/@amplitude/analytics-browser/lib/esm/storage/local-storage.js

Possible Solution

Implement a check within the SDK to gracefully handle scenarios where localStorage access is not available. This could include try-catch blocks around localStorage access or alternative storage mechanisms when localStorage is not accessible.

Steps to Reproduce

  1. Embed a webpage in a cross-origin iframe.
  2. Integrate the Amplitude into the webpage.
  3. Load the webpage within the iframe and observe the JavaScript console for errors related to localStorage access.
  4. Notice that the application crashes or behaves unexpectedly.

Environment

  • JS SDK Version: 2.1.2
  • Installation Method: Yarn
  • Browser and Version: Chrome - Version 119.0.6045.199
@batuhan-kajabi batuhan-kajabi added the bug Something isn't working label Jan 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant