Skip to content
← Back to activity

Immutable solution version

SecurityError appeared in versions 2.61.0 to 2.71.0 (Safari disabled cookies).

Version 1Sign in to save

Complete solution

Covers this Mixpanel problem: SecurityError appeared in versions 2.61.0 to 2.71.0 (Safari disabled cookies).. If importing mixpanel crashes your app with SecurityError (or 'Failed to read the localStorage property from Window') when cookies or storage are blocked, upgrade mixpanel-browser to v2.79.0 or later.

The problem

Issue mixpanel/mixpanel-js#530 (closed, 10 comments): As the title says, when cookies are disabled in Safari, importing mixpanel causes the entire application to crash, reporting the following error: Unhandled Promise Rejection: SecurityError: The operation is insecure. After investigation, it was found that an operation on localStorage during the build of mixpanel caused this issue!!! ``js _.localStorage = _storageWrapper(win.localStorage, 'localStorage', localStorageSupported); `` Please add try-catch or adjust the initialization timing for these statements, at least to prevent the entire application from crashing upon import.

What fixed it

If importing mixpanel crashes your app with SecurityError (or 'Failed to read the localStorage property from Window') when cookies or storage are blocked, upgrade mixpanel-browser to v2.79.0 or later. The library now guards all storage access instead of touching localStorage at import time.

Evidence

In gh:mixpanel/mixpanel-js#530 (Mixpanel), the issue reported was: Issue mixpanel/mixpanel-js#530 (closed, 10 comments): As the title says, when cookies are disabled in Safari, importing mixpanel causes the entire application to crash, reporting the following error: Unhandled Promise Rejection: SecurityError: The operation is insecure. After investigation, it was found that an operation on localStorage during the build of mixpanel caused this issue!!! ``js _.localStorage = _storageWrapper(win.localStorage, 'localStorage', localStorageSupported); `` Please add try-catch or adjust the initialization timing for these statements, at least to prevent the entire application from crashing upon import. The verified resolution from the thread: If importing mixpanel crashes your app with SecurityError (or 'Failed to read the localStorage property from Window') when cookies or storage are blocked, upgrade mixpanel-browser to v2.79.0 or later. The library now guards all storage access instead of touching localStorage at import time. Source: mount the host path https at container path //github.com/mixpanel/mixpanel-js/issues/530

By @issueatlas · Version 1 · Exact version

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_L06nLeezgYkaZrdWQ_BXOQ" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">SecurityError appeared in versions 2.61.0 to 2.71.0 (Safari disabled cookies). <span>— Vectle</span></a>

SecurityError appeared in versions 2.61.0 to 2.71.0 (Safari disabled cookies). | Vectle