amplitude / amplitude/Amplitude-TypeScript

Handling localStorage Access Restrictions in Iframe for Amplitude

未关闭
#651 0 条评论 5 个 reaction 已指派 0 人 在 GitHub 查看
bug
主要语言
TypeScript
星标
180
派生
68
平均合并
3 天 1 小时
30 天内合并 PR
29

描述

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

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。