jQuery 本地存储错误 - NS_ERROR_FILE_CORRUPTED - firefox

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18877643/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 22:40:57  来源:igfitidea点击:

Error in local storage - NS_ERROR_FILE_CORRUPTED - firefox

javascriptjqueryfirefoxlocal-storage

提问by Juan Jardim

I've been working in a web application and I'm using local storage. But for some Firefox users I notice that they're having the following error:

我一直在使用 Web 应用程序,并且正在使用本地存储。但是对于一些 Firefox 用户,我注意到他们有以下错误:

NS_ERROR_FILE_CORRUPTED: Component returned failure code: 0x8052000b (NS_ERROR_FILE_CORRUPTED) [nsIDOMStorage.setItem]

NS_ERROR_FILE_CORRUPTED:组件返回失败代码:0x8052000b (NS_ERROR_FILE_CORRUPTED) [nsIDOMStorage.setItem]

when it called the function:

当它调用函数时:

function setLocalStorageItem(key, value){ 
        localStorage.setItem(key, JSON.stringify(value));
}

It's is a way to avoid this error?

这是避免此错误的一种方法吗?

采纳答案by apsillers

This is a browser-level error: you probably didn't do anything wrong to cause this error. The browser (or the the SQLite library it uses) either did something wrong, or the file was left in an invalid state due to a hardware problem.

这是浏览器级别的错误:您可能没有做错任何事情来导致此错误。浏览器(或它使用的 SQLite 库)要么做错了,要么由于硬件问题导致文件处于无效状态。

You can't really prevent this issue, except by joining the Firefox development team and making the browser's storage system more fault-resistant. There doesn't seem to be any way to restore data from this error, so what you'll have to do is detect this error and tell users how to blow away their browser storage according to this MDN post:

你无法真正阻止这个问题,除非加入 Firefox 开发团队并让浏览器的存储系统更加抗故障。似乎没有任何方法可以从此错误中恢复数据,因此您需要做的是检测此错误并根据此 MDN 帖子告诉用户如何清除他们的浏览器存储空间:

try {
    setLocalStorageItem(key, value);
} catch(e) {
    if(e.name == "NS_ERROR_FILE_CORRUPTED") {
        showMessageSomehow("Sorry, it looks like your browser storage has been corrupted. Please clear your storage by going to Tools -> Clear Recent History -> Cookies and set time range to 'Everything'. This will remove the corrupted browser storage across all sites.");
    }
}

Note that the catchblock should verify that the error is an NS_ERROR_FILE_CORRUPTEDerror. I think my check on e.nameis correct, but you should verify it for yourself.

请注意,该catch块应验证错误是否为NS_ERROR_FILE_CORRUPTED错误。我认为我的检查e.name是正确的,但你应该自己验证一下。

回答by Volker E.

After an OS crash files within the Firefox profile folder might be corrupt and lead to non-functional websites (in my case ironically the Firefox marketplace). Here, webappsstore.sqlitewas affected.

Firefox 配置文件夹中的操作系统崩溃文件可能会损坏并导致无法正常运行的网站(在我的情况下具有讽刺意味的是 Firefox 市场)。在这里,webappsstore.sqlite受到了影响。

As user @Oli stated over at Ask Ubuntu

正如用户@Oli 在Ask Ubuntu 上所说的那样

Firefox stores its HTML5 data in a file called webappsstore.sqlite. That's sitting in your profile directory which lurks somewhere in ~/.mozilla/firefox/....default/ (depending on what your profile is called).

Move that out the way and restart Firefox and everything will come back to life.

Firefox 将其 HTML5 数据存储在名为 webappsstore.sqlite 的文件中。它位于您的个人资料目录中,该目录潜伏在 ~/.mozilla/firefox/....default/(取决于您的个人资料的名称)中的某处。

将其移开并重新启动 Firefox,一切都会恢复生机。

More: https://developer.mozilla.org/en/dom/storage

更多:https: //developer.mozilla.org/en/dom/storage

If deleted/moved out of your profile folder, Firefox builds a new, sanitized webappsstore.sqlitefile. Worked for me.
Information on where to find your profile folder can be accessed here.

如果删除/移出您的配置文件文件夹,Firefox 会构建一个新的、经过清理的webappsstore.sqlite文件。为我工作。
可以在此处访问有关在何处找到您的配置文件文件夹的信息

回答by Jeff Widman

Clearing everything via the Firefox preferences may not fully clear the local storage where the corrupted SQLite file resides.

通过 Firefox 首选项清除所有内容可能无法完全清除损坏的 SQLite 文件所在的本地存储。

At this point, you have two options:

此时,您有两个选择:

localStorage.clear()
sessionStorage.clear()
  • Use the terminal to delete the corrupted SQLite file and force Firefox to rebuild it.
  • 使用终端删除损坏的 SQLite 文件并强制 Firefox 重建它。

Steps for macOS users:

macOS 用户的步骤:

  1. cd /Users/myusername/Library/Application Support/Firefox/Profiles/.....default/
  2. rm webappsstore.sqlite
  3. Verify no other files corrupted using this script from TheConstructor:

    for i in $(find . -name '*.sqlite'); do echo "$i"; echo "PRAGMA integrity_check;" | sqlite3 -bail "$i"; done

  4. Restart Firefox and reload the page.
  1. cd /Users/myusername/Library/Application Support/Firefox/Profiles/.....default/
  2. rm webappsstore.sqlite
  3. 使用TheConstructor 中的此脚本验证没有其他文件损坏:

    for i in $(find . -name '*.sqlite'); do echo "$i"; echo "PRAGMA integrity_check;" | sqlite3 -bail "$i"; done

  4. 重新启动 Firefox 并重新加载页面。

回答by Peter Fischaleck

Had this problem just pop up with one of our clients.

如果我们的一位客户突然出现这个问题。

Completely deleting the historyand (I guess that is the important part) offline website datasolved the problem.

完全删除history和(我想这是重要的部分)offline website data解决了问题。

(Firefox Version 40.0.3)

(火狐版本40.0.3

回答by ddreian

Not sure if this helps but I have this issue on Jira. I restarted Firefox with addons disabled and wen to Jira and it worked. Then I stopped Firefox and restarted it with Addons enabled and it worked again. I don't know why this worked :) I use Firefox Developer edition 48.0a2 (2016-05-24)

不确定这是否有帮助,但我在 Jira 上遇到了这个问题。我在禁用插件的情况下重新启动了 Firefox,然后转到 Jira 并且它工作正常。然后我停止了 Firefox 并在启用插件的情况下重新启动它,它再次工作。我不知道为什么会这样 :) 我使用 Firefox Developer edition 48.0a2 (2016-05-24)