Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best Method to Save Data in a Firefox Add-on

For example let us say that we want to save a list of URLs and this list is updated dynamically. The following are the ways that I see this can be done.
1) Save in a text file
2) Save in a SQLite data base
3) Save in a preference (I know preferences are for storing preferences but is there any drawback of using a preference?)

What is the best method to save data related to a Firefox add-on? If a generic answer is not possible, what is the best method for a situation like the example above? And why do you think that such a method is appropriate and others are not?

like image 292
Can't Tell Avatar asked Apr 23 '11 01:04

Can't Tell


People also ask

How can I save my Firefox data?

Right-clickHold down the Ctrl key while you click on your profile folder (e.g. xxxxxxxx. default), and select Copy. Right-clickHold down the Ctrl key while you click the backup location (e.g. a USB-stick or a blank CD-RW disc), and select Paste .

Does Firefox have a data saver?

Extension MetadataTell websites that you prefer to save data and costs. At websites' discretion, you may see lower quality images and fewer media elements as webpages adjust to reduce data downloads. The extension works by sending the Save-Data: on HTTP header with every request.


1 Answers

Preferences are simple and lightweight, but your storage requirements could outgrow preferences. SQLite is good for larger sets of data that need fast query capabilities. I find using file-based storage simple and effective. Just make sure you use async I/O whenever possible.

Saving the data to a JSON (or other format) text file is a simple thing to do. The Firefox session store does the same thing. When saving, use the profile folder location, maybe even make a sub folder.

MDN has notes on finding the profile folder and reading/writing a text file:

  • Getting files in special directories
  • Reading from a file

You can use the nsIJSON component in older releases or the built-in JSON object in current releases of Firefox: https://developer.mozilla.org/en/JSON

like image 91
Mark Finkle Avatar answered Sep 27 '22 22:09

Mark Finkle