简体   繁体   English

本地存储错误 - NS_ERROR_FILE_CORRUPTED - firefox

[英]Error in local storage - NS_ERROR_FILE_CORRUPTED - firefox

I've been working in a web application and I'm using local storage.我一直在 web 应用程序中工作,并且我正在使用本地存储。 But for some Firefox users I notice that they're having the following error:但是对于某些 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 时:

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

It's is a way to avoid this error?这是避免此错误的方法吗?

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

As user @Oli stated over at Ask Ubuntu正如用户@Oli 在Ask Ubuntu 上所说的那样

Firefox stores its HTML5 data in a file called webappsstore.sqlite. Firefox 将其 HTML5 数据存储在名为 webappsstore.sqlite 的文件中。 That's sitting in your profile directory which lurks somewhere in ~/.mozilla/firefox/....default/ (depending on what your profile is called).它位于您的个人资料目录中,该目录潜伏在 ~/.mozilla/firefox/....default/(取决于您的个人资料的名称)中的某处。

Move that out the way and restart Firefox and everything will come back to life.将其移开并重新启动 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.sqlite file.如果删除/移出您的配置文件文件夹,Firefox 会构建一个新的、经过清理的webappsstore.sqlite文件。 Worked for me.为我工作。
Information on where to find your profile folder can be accessed here .可以在此处访问有关在何处找到您的配置文件文件夹的信息

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.你无法真正阻止这个问题,除非加入 Firefox 开发团队并让浏览器的存储系统更加抗故障。 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 :似乎没有任何方法可以从此错误中恢复数据,因此您需要做的是检测此错误并根据此 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 catch block should verify that the error is an NS_ERROR_FILE_CORRUPTED error.请注意, catch块应验证错误是否为NS_ERROR_FILE_CORRUPTED错误。 I think my check on e.name is correct, but you should verify it for yourself.我认为我对e.name检查是正确的,但您应该自己验证。

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 :使用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.重新启动 Firefox 并重新加载页面。

So when I had this issue I went though the suggestions in the answers and they did not really help.因此,当我遇到这个问题时,我仔细考虑了答案中的建议,但它们并没有真正帮助。 Note that it was crucial to me to not lose history and preferable to not have to re-login on every site请注意,对我来说至关重要的是不要丢失历史记录并且最好不必在每个站点上重新登录

What did help was nuking the whole storage directory inside Firefox profile有用的是核对 Firefox 配置文件中的整个storage目录

UPD: I lost add on configurations this way UPD:我以这种方式丢失了配置

What did not work:什么没有奏效:

  • removing webappsstore.sqlite in Firefox profile directory删除webappsstore.sqlite配置文件目录中的 webappsstore.sqlite
  • removing storage.sqlite删除storage.sqlite
  • checking sqlite files using a script mentioned in one of the answers, it returned ok for all the files使用其中一个答案中提到的脚本检查ok个文件,所有文件返回正常
  • removing sqlite files for specific website that was broken (inside storage directory)为损坏的特定网站删除 sqlite 个文件(在storage目录内)

Had this problem just pop up with one of our clients.如果我们的一位客户突然出现这个问题。

Completely deleting the history and (I guess that is the important part) offline website data solved the problem.完全删除history和(我想这是重要的部分) offline website data解决了这个问题。

(Firefox Version 40.0.3 ) (火狐版本40.0.3

In your profile folder, use a sqlite database client to delete rows in storage/ls-archive.sqlite , where the key is the reverse ordered string of your problematic domain name.在您的配置文件文件夹中,使用 sqlite 数据库客户端删除storage/ls-archive.sqlite中的行,其中键是您有问题的域名的倒序字符串。 You might also need to remove storage/default/<your-problematic-domain-name> folders.您可能还需要删除storage/default/<your-problematic-domain-name>文件夹。 This way you don't need to remove all your local storage in your profile.这样您就不需要删除配置文件中的所有本地存储。

Not sure if this helps but I have this issue on Jira.不确定这是否有帮助,但我在 Jira 上遇到了这个问题。 I restarted Firefox with addons disabled and wen to Jira and it worked.我在禁用插件的情况下重新启动了 Firefox,然后转到 Jira 并且它工作正常。 Then I stopped Firefox and restarted it with Addons enabled and it worked again.然后我停止了 Firefox 并在启用插件的情况下重新启动它,它再次工作。 I don't know why this worked :) I use Firefox Developer edition 48.0a2 (2016-05-24)我不知道为什么会这样 :) 我使用 Firefox Developer edition 48.0a2 (2016-05-24)

Firefox on MacOS Big Sur (11.4) MacOS Big Sur 上的 Firefox (11.4)

I was living with this problem for over a month, hoping that a new version of Firefox will come and it will be fixed.我被这个问题困扰了一个多月,希望有新版本的 Firefox 出现并修复它。 I didn't, at least until version 89.0.2, July 2021, that I am currently on.至少在 2021 年 7 月 89.0.2 版之前,我没有使用过。

So, I had a bookmarklet for the LocalStorage and SessionStorage clear solution (mentioned on the other answer .) My bookmarklet was javascript:localStorage.clear();sessionStorage.clear();所以,我有一个 LocalStorage 和 SessionStorage clear 解决方案的书签(在另一个答案中提到。)我的书签是javascript:localStorage.clear();sessionStorage.clear(); and I was hitting it every time I was running into a page that not responding and the console (F12) in Firefox was showing this NS_ERROR_FILE_CORRUPTED error.每次我遇到一个没有响应的页面并且Firefox中的控制台(F12)显示此NS_ERROR_FILE_CORRUPTED错误时,我都会点击它。

However, it was so annoying and this solution wasn't working on certain websites (eg AWS).然而,这太烦人了,这个解决方案在某些网站(例如 AWS)上不起作用。

I even downloaded and reinstalled Firefox and cleared ~/Library/Firefox and ~/Library/Mozilla and they didn't help either.我什至下载并重新安装了 Firefox 并清除了~/Library/Firefox~/Library/Mozilla ,它们也没有帮助。

Solution: Clear Profile Folder (and then Restore your Profile)解决方案:清除配置文件文件夹(然后恢复您的配置文件)

It was crucial for me not to lose my bookmarks and passwords in Firefox.在 Firefox 中不要丢失我的书签和密码对我来说至关重要。

Here is what finally worked for me:这是最终对我有用的方法:

  1. Make sure you create an account in Mozilla/Firefox and turn on Syncing.确保您在 Mozilla/Firefox 中创建一个帐户并打开同步。 (top right button.) Optional: It's helpful to install Firefox on your phone and sync to make sure you have a live backup of your data and you are not losing passwords and bookmarks if things go wrong. (右上角的按钮。) 可选:在您的手机上安装 Firefox 并进行同步会很有帮助,以确保您有数据的实时备份,并且在出现问题时不会丢失密码和书签。

  2. Open Finder.打开查找器。 Go to ~/Library/Application Support .转到~/Library/Application Support Move Firefox folder to trash.Firefox文件夹移至垃圾箱。

  3. Restart Firefox.重启火狐。 (I have a bookmark for about:restartrequired that comes handy.) (我有一个about:restartrequired的书签,很方便。)

  4. Relogin to your profile in Firefox and sync.在 Firefox 中重新登录您的个人资料并同步。

Caveats注意事项

  1. Your bookmarks are going to be out of order in the bookmark bar, and their icons are going to be blank until your first visit.您的书签将在书签栏中出现乱序,并且在您第一次访问之前,它们的图标将是空白的。
  2. You have to login to every account (eg GMails) manually and one by one.您必须手动并一一登录每个帐户(例如 GMails)。 It should be straightforward if you have the passwords saved.如果您保存了密码,这应该很简单。

I'm on Firefox 97 (2022).我在 Firefox 97 (2022)。 Deleting webappsstore.sqlite and storage.sqlite didn't resolve the issue, nor did deleting [Profile]/storage/default.删除 webappsstore.sqlite 和 storage.sqlite 没有解决问题,删除 [Profile]/storage/default 也没有解决。 YMMV. YMMV。

What did however resolve this issue is:然而解决这个问题的是:

  • Settings -> Privacy & Security -> History设置 -> 隐私和安全 -> 历史记录
  • Clear History...清除历史记录...
  • Time Range: Everything时间范围:一切
  • Under "History," only select: Cache在“历史记录”下,只有 select:缓存
  • Under "Data," only select: Site Settings and Offline Website Data under “数据”下只有select:网站设置和离线网站数据下

And then reload the website(s) that are failing, and they should now be working.然后重新加载失败的网站,它们现在应该可以正常工作了。 Only cost is losing site-specific settings.唯一的代价是丢失特定于站点的设置。

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

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