Move database format from Chrome to Firefox

I have a Chrome extension that stores data using json string in localStorage variable. I am trying to create a version of this extension for firefox. But in firefox, localStorage does not seem to work for extensions.

Is it possible to just save a json string in firefox? Thank.

+3
source share
1 answer

If you use the Firefox Addon SDK for your extension, you can use the built-in simple storage module . It provides an object storagethat your code can handle as a regular javascript object, but Firefox will keep it persistent for you.

A simplified example looks like this:

// load the simple storage module
var storage = require('simple-storage').storage;

// write a value to the key "bacon"
storage.bacon = JSON.stringify({"tasty": "is bacon"});

// do stuff, retrieve the value later and pass it to a function
eat(storage.bacon);

storage.bacon .

+2

All Articles