amplitude / amplitude/Amplitude-TypeScript

Handling localStorage Access Restrictions in Iframe for Amplitude

Ouverte
#651 0 commentaires 5 réactions 0 personnes assignées Voir sur GitHub
bug
Langage dominant
TypeScript
Étoiles
180
Forks
68
Merge moyen
3 j 1 h
PR mergées (30 j)
29

Description

## 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

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.