Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LocalStorage in Firefox extension

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.

like image 999
user2796599 Avatar asked Feb 15 '23 05:02

user2796599


2 Answers

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.

like image 143
jsantell Avatar answered Feb 17 '23 19:02

jsantell


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.

like image 20
jmort253 Avatar answered Feb 17 '23 21:02

jmort253