简体   繁体   English

Localstorage 在本地网页上不起作用:安全错误

[英]Localstorage does not work on local webpage: security error

When using my webpage ( http://localhost/mypage.html ) accessing localStorage issues a security error:使用我的网页 ( http://localhost/mypage.html ) 访问 localStorage 时出现安全错误:

Uncaught DOMException: Failed to read the 'localStorage' property from 'Window': Access is denied for this document.未捕获的 DOMException:无法从“Window”读取“localStorage”属性:拒绝访问此文档。

It is just a simple line这只是一条简单的线

res = localStorage.getItem(name);

and even乃至

console.log(localStorage); 

issues the same error.发出同样的错误。

But it is a LOCAL site, so no cross domains are used.但它是本地站点,因此不使用跨域。

What goes wrong here?这里出了什么问题?

This problem is related to a Chromium bug which is now fixed.此问题与现已修复的 Chromium 错误有关。 See https://community.brave.com/t/html5-localstorage/100843参见https://community.brave.com/t/html5-localstorage/100843

You can check if your current version is affected with this JSFiddle: https://jsfiddle.net/6sm54/2/您可以检查您当前的版本是否受到此 JSFiddle 的影响: https://jsfiddle.net/6sm54/2/

function lsTest(){ 
    var test = 'test';
    try {
      localStorage.setItem(test, test);
      localStorage.removeItem(test);
      return true;
    } catch(e) {
      return false;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM