Juan Jardim
Juan Jardim

Reputation: 2252

Error in local storage - NS_ERROR_FILE_CORRUPTED - firefox

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:

NS_ERROR_FILE_CORRUPTED: Component returned failure code: 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?

Upvotes: 58

Views: 47524

Answers (9)

oldherl
oldherl

Reputation: 240

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. You might also need to remove storage/default/<your-problematic-domain-name> folders. This way you don't need to remove all your local storage in your profile.

Upvotes: 1

Safari Jones
Safari Jones

Reputation: 500

I'm on Firefox 97 (2022). Deleting webappsstore.sqlite and storage.sqlite didn't resolve the issue, nor did deleting [Profile]/storage/default. YMMV.

What did however resolve this issue is:

  • Settings -> Privacy & Security -> History
  • Clear History...
  • Time Range: Everything
  • Under "History," only select: Cache
  • Under "Data," only select: Site Settings and Offline Website Data under

And then reload the website(s) that are failing, and they should now be working. Only cost is losing site-specific settings.

Upvotes: 1

yefrem
yefrem

Reputation: 666

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

UPD: I lost add on configurations this way

What did not work:

  • removing webappsstore.sqlite in Firefox profile directory
  • removing storage.sqlite
  • checking sqlite files using a script mentioned in one of the answers, it returned ok for all the files
  • removing sqlite files for specific website that was broken (inside storage directory)

Upvotes: 2

Aidin
Aidin

Reputation: 30007

Firefox on MacOS Big Sur (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. I didn't, at least until version 89.0.2, July 2021 92.0 Sep 2021, that I am currently on.

Why is it happening?

As other answers mention, it happens when your machine crashes and Firefox leaves its sqlite storage files in a broken state on disk. Yes, Mozilla should have been more resilient, but it's not. :(

What should I do now?

I downloaded and reinstalled Firefox and cleared ~/Library/Firefox and ~/Library/Mozilla and they didn't help either.

I have found that you have 3 solutions to try. Depending on how severe the damaged file is, one of them might work.


Solution 1: Clear localStorage and sessionStorage

Hit F12 (Tools > Browser Tools > Browser Console) and paste

localStorage.clear();sessionStorage.clear()

I have a bookmarklet for it solution (as mentioned on the other answer.) My bookmarklet is javascript:localStorage.clear();sessionStorage.clear(); and I hit 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.

However, it is so annoying and this solution isn't working on certain websites (e.g. AWS, or Jira).


Solution 2: Manual deletion of certain sqlite files

Based on the other answers (and the comment from TheConstructor), here is what you can do in terminal:

  1. Go to ~/Library/Application Support/Firefox/Profiles/
  2. ls -al and then cd into the folder that's touched recently. (If you have a Mozilla account to sync bookmarks and password with your phone, you are NOT on default.)
  3. Run for i in $(find . -name '*.sqlite'); do echo "$i"; echo "PRAGMA integrity_check;" | sqlite3 -bail "$i" 2>&1; done | grep -v ok | grep -v locked and look for any output that's not a ./xxx/yyy.sqlite. (e.g. Main freelist: size is 0 but should be 4.) The file above the error is the corrupted file.
  4. Move corrupted file(s) away. (either rm them, or mv somewhere else.)
  5. Restart Firefox. (I have a bookmark to about:restartrequired which is handy.)

It should hopefully fix the issue with minimal damage.


Solution 3: Clear Profile Folder (and then Restore your Profile)

If solution 2 doesn't work, you have to clear the entire local data for the profile.

It was crucial for me not to lose my bookmarks and passwords in Firefox.

Here is what finally worked for me:

  1. Make sure you create an account in Mozilla/Firefox and turn on Syncing. (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.

  2. Open Finder. Go to ~/Library/Application Support. Move Firefox folder to trash.

  3. Restart Firefox. (I have a bookmark for about:restartrequired that comes handy.)

  4. Relogin to your profile in Firefox and sync.

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 (e.g. GMails) manually and one by one. It should be straightforward if you have the passwords saved.

Upvotes: 6

Jeff Widman
Jeff Widman

Reputation: 23492

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

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.

Steps for macOS users:

  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.

Upvotes: 38

ddreian
ddreian

Reputation: 1856

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)

Upvotes: 0

Peter Fischaleck
Peter Fischaleck

Reputation: 342

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.

(Firefox Version 40.0.3)

Upvotes: 1

Volker E.
Volker E.

Reputation: 6035

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.sqlite was affected.

As user @Oli stated over at 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.

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

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

Upvotes: 67

apsillers
apsillers

Reputation: 115950

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.

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:

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. I think my check on e.name is correct, but you should verify it for yourself.

Upvotes: 40

Related Questions