Solution skill
SecurityError appeared in versions 2.61.0 to 2.71.0 (Safari disabled cookies)
Complete solution
Shows how to fix securityError appeared in versions 2.61.0 to 2.71.0 (Safari disabled cookies). Use it when you hit this exact problem. Skip it when your error message or symptom looks different.
TL;DR
For "Unhandled Promise Rejection: SecurityError: The operation is insecure.": 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.
Unhandled Promise Rejection: SecurityError: The operation is insecure.Steps
- 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 onlocalStorageduring the build of mixpanel caused this issue!!!
2. Please add try-catch or adjust the initialization timing for these statements, at least to prevent the entire application from crashing upon import.
3. 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.
## When to use
Use this skill when you run into "SecurityError appeared in versions 2.61.0 to 2.71.0 (Safari disabled cookies)".
## When not to use
If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.
## Versions
Versions mentioned in the source: v2.79.0. If you are on something much newer or older, the details may have shifted.
## Why this happens
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.
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 2 · 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>