【问题标题】:LocalStorage is not working on Firefox. Getting Security errorLocalStorage 不适用于 Firefox。获取安全错误
【发布时间】:2019-04-12 12:42:03
【问题描述】:

我正在尝试在浏览器本地存储中存储一些信息。我的代码在 Chrome 上运行 fine 但是,我在 Firefox 和 Safari 上遇到安全错误和以下警告

Firefox 版本:63.0.1(64 位)

从本地存储中检索数据时出现错误和警告:

堆栈跟踪:

ERROR DOMException: "The operation is insecure." EventDetailsComponent.html:1
View_EventDetailsComponent_0
EventDetailsComponent.html:1 proxyClass compiler.js:17129
./node_modules/@angular/core/fesm5/core.js/DebugContext_.prototype.logError
core.js:20684
./node_modules/@angular/core/fesm5/core.js/ErrorHandler.prototype.handleError
core.js:12632
./node_modules/@angular/core/fesm5/core.js/ApplicationRef.prototype.tick/<
core.js:14878:54
./node_modules/zone.js/dist/zone.js/</ZoneDelegate.prototype.invoke
zone.js:388
./node_modules/zone.js/dist/zone.js/</Zone.prototype.run
zone.js:138

错误信息:

[WDS] Disconnected! vendor.js:157169:5 close

ERROR DOMException: "The operation is insecure." EventDetailsComponent.html:1
View_EventDetailsComponent_0 EventDetailsComponent.html:1 proxyClass

Request to access cookie or storage on “http://localhost:4200/” was blocked because we are blocking all storage access requests.

本地存储服务:

     public getFav(): FavoriteStorage[] {
return JSON.parse(window.localStorage.getItem('favlist'));

          }
private setLocalStorageFavList(favL: FavoriteStorage[]): void {
    window.localStorage.setItem('favlist', JSON.stringify({ favList: favL }));
  }

我试过 localStorage.setItem()/getItem() 而不是 window.localStorage.setItem() /getItem()

【问题讨论】:

    标签: angular firefox local-storage


    【解决方案1】:

    localStorage 与 globalStorage[location.hostname] 相同,具有 范围限定为 HTML5 来源的例外(方案 + 主机名 + 非标准端口)

    旧的 Firefox 行为存在错误,该错误已得到修复。根据规范,设置 document.domain 应该对 localStorage 的行为绝对没有影响,因此在您的情况下,您尝试为不同的域设置 localStorage,这是不允许的。

    有关详细信息,请参阅 https://bugzilla.mozilla.org/show_bug.cgi?id=495337 和 localStorage 规范。

    更多内容请关注documentation

    【讨论】:

    • 我没有明白你的意思——“试图为不同的域设置本地存储”。我正在存储一个带有 NO 域名的 JSON,例如 xxx.xxx.com 或 yyy.com 或 zzz.com/image.jpg,其中包含端口:4200 在我的 locahost 上的键或值。所有代码都在浏览器上。
    猜你喜欢
    • 2013-02-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-05
    • 2017-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多