Has Firefox extension personal LocalStorage? And how can I get access to it?
I know about window.content.localStorage
, but it the specific localStorage of the current page, not like in Google Chrome, where each extension has personal background page.
You can use the simple-storage module for storing content specifically for your addon that is not bound to a specific page like localStorage, and you also can use the indexed-db module, which is a bit more robust, and we are kind of moving away from simple-storage.
simple-storage would be an ideal solution, but if you're using the Add-on Builder Helper it's not ideal because the storage gets flushed every time you make a change to the code and reload the app. Thus, it's impossible to test that your code works properly without actually building the extension and going to test it in another browser profile, making it hard to tweak the code and make minor changes.
Instead, I used the simple-prefs module, which did actually persist across restarts:
var prefs = require("simple-prefs").prefs;
The downside is everything has to be serialized as a string, so the development overhead is a little bit more complicated, but once you get it setup you can then test your code more easily without having to build the XPI for each minor change, something the Add-on Builder is supposed to help you avoid.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With