Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

store preferences in google chrome extentions

Using firefox, I can store extension preferences using Components.classes["@mozilla.org/preferences-service;1"] .getService(Components.interfaces.nsIPrefService);

What interface can I use to store preferences in Chrome? And do they get overwritten on an extension update?

Thanks

like image 331
rack1 Avatar asked Jan 29 '26 17:01

rack1


2 Answers

You can use the localStorage API. See http://code.google.com/chrome/extensions/options.html for an example of building an options page with this, but most simply you can do:

localStorage['foo'] = 'bar';   // Store data
var foo = localStorage['foo']; // Get data

This data won't be wiped out on extension update, either.

like image 77
Arne Roomann-Kurrik Avatar answered Feb 01 '26 11:02

Arne Roomann-Kurrik


The new HTML5 feature to persist data locally (localStorage) should help you here.

In addition to coockies, now there are session and local storage objects, as well as, a simple version of relational database (all storing data on your local harddisk).

One hint when storing/retrieving objects to localStorage ... it is a simple implementation of the Map interface, so the safest way to persist your object is by serializing them via JSON.stringify function and parse retrieved string with JSON.parse.

like image 30
Draško Kokić Avatar answered Feb 01 '26 10:02

Draško Kokić



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!