Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.x] Access to Local Storage can be blocked in Chrome #997

Closed
olafcm opened this issue Feb 6, 2020 · 9 comments · Fixed by #999
Closed

[4.x] Access to Local Storage can be blocked in Chrome #997

olafcm opened this issue Feb 6, 2020 · 9 comments · Fixed by #999

Comments

@olafcm
Copy link

olafcm commented Feb 6, 2020

We updated to v4 of the client.
Since then we started to receive the following error for Chrome users:

Failed to read the 'localStorage' property from 'Window': Access is denied for this document.

The issue happens here:

function u(e) {
  var t = e.localStorage || window.localStorage,
    r = "algoliasearch-client-js-".concat(e.key),
    n = function() {
      return JSON.parse(t.getItem(r) || "{}")
    };

More info: https://www.chromium.org/for-testers/bug-reporting-guidelines/uncaught-securityerror-failed-to-read-the-localstorage-property-from-window-access-is-denied-for-this-document

Is it possible for the client to detect if the LocalStorage is available? I.e. use: https://github.com/Modernizr/Modernizr/blob/master/feature-detects/storage/localstorage.js

Thank you

@nunomaduro
Copy link
Contributor

Thanks for reporting this issue, I will investigate this tomorrow morning. 👍

@nunomaduro
Copy link
Contributor

@olafcm Just to be clear, your search is working, but you got the warning on the chrome console right?

@olafcm
Copy link
Author

olafcm commented Feb 6, 2020

Yes, I tested it and search works. It probably only affects the search results caching.

@nunomaduro
Copy link
Contributor

nunomaduro commented Feb 6, 2020

I just don't preserve the state of the hosts after the refresh, and it uses the fallback in memory cache:

.

I will see if we can avoid the warning on the console. Otherwise everything seems to be working as expected.

@Haroenv
Copy link
Contributor

Haroenv commented Feb 7, 2020

I wonder if adding a .catch which still throws, but without the default error message will avoid it showing on the console.

@nunomaduro
Copy link
Contributor

We are using catch on the FallbackableCache:

return current.get(key, defaultValue, events).catch(() => {

That performs a catch on the driver to fallback to the next one. Leet me investigate this.

@nunomaduro
Copy link
Contributor

@olafcm can you also review the pull request that I just made?

@nunomaduro
Copy link
Contributor

The bug has been fixed in version 4.0.2. ⚡️

@olafcm
Copy link
Author

olafcm commented Feb 7, 2020

Works perfect, thank you very much for the perfect and quick fix @nunomaduro 🎈

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants