orestbida / cookieconsent

:cookie: Simple cross-browser cookie-consent plugin written in vanilla js
https://playground.cookieconsent.orestbida.com/
MIT License
3.68k stars 388 forks source link

[Bug]: using LocalStorage if Browser rejects storing local data #609

Closed boldtrn closed 6 months ago

boldtrn commented 6 months ago

Expected Behavior

One issue with localStorage always happens if browser are set up to not allow storing any local data.

Calling any localStorage methods throws a SecurityError.

No exception is thrown, when the browser is configured to not allow storing data.

See also: https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage#exceptions

Current Behavior

Unhandled Promise Rejection: SecurityError: The operation is insecure.

Steps to reproduce

Don't allow any data to be stored, load the library, the Error is thrown on library load as the localStorage is called to see if any consent is stored.

Proposed fix or additional info.

try/catch for methods accessing localStorage.

Version

latest main

On which browser do you see the issue?

No response

boldtrn commented 6 months ago

For reference, we had the same issue with Klaro: https://github.com/klaro-org/privacy-manager/issues/366