rack1
rack1

Reputation: 31

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

Upvotes: 3

Views: 656

Answers (2)

Draško Kokić
Draško Kokić

Reputation: 1290

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.

Upvotes: 1

Arne Roomann-Kurrik
Arne Roomann-Kurrik

Reputation: 1072

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.

Upvotes: 4

Related Questions