Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to persistently store data in `localStorage` when using `jpm run` for a Firefox Add-on SDK extension

I am working on Firefox extension and I need to store date in localStorage for login property.

I used simple storage but simple storage loses data after restart.

So, please let me know how to store data in localStorage.

like image 876
mahipal negi Avatar asked Dec 08 '25 06:12

mahipal negi


1 Answers

You are probably using jpm run to test your add-on. jpm run uses a fresh, temporary profile each time you execute it. If you want any data to persist from one execution to another you will need to use the -p or --profile= option to specify a profile to use for that run. See Using profiles on MDN. You can specify either the profile name, or the path to the profile. The lack of persistence of just using jpm run will be an issue for any storage which is placed in the profile, or profile directory be it a preference with simple-prefs, data using simple-storage, a file using io/file, a database using SQLite database, or any other method. This is explicitly stated on multiple pages, including the simple-storage page.

Examples (from MDN):

jpm run --profile boogaloo
jpm run --profile path/to/boogaloo

If you want to create a new profile to use for testing, you can use the profile manager. You can start the profile manager by starting Firefox with any of the options -p, -P, or -ProfileManager. Normally, you will need to exit out of any currently running Firefox instance in order to start a new version of Firefox. However, it is also possible to start a new instance while having Firefox open with a different profile by using the -no-remote option. For example, on 64-bit Windows, to start the Firefox profile manager, I normally use:

"C:\Program Files (x86)\Mozilla Firefox\firefox.exe" -no-remote -ProfileManager

If you are really wanting to use local storage, you should store the data within the profile directory, so you will still need to do the above steps to use a specified profile. You will want to look at io/file, and will need to open() the file and then read or write it using text-streams or byte-streams. The next logical question is where it should be stored, but that is another question: Where to save files from Firefox add-on?

like image 184
Makyen Avatar answered Dec 09 '25 18:12

Makyen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!