I am new to extension development. Right now I am testing a Firefox extension developed with the Add-on SDK. I want to use HTM5 localstorage to store something from one of the background scripts in my extension, which will be fetched from a different background script of the same extension. npm (Node Packet Manager) has been used, so the problem is I am not able to use browser localStorage object, ReferenceError: localStorage is not defined
is what I get.
By surfing I came to know about node-localstorage. I am following the instructions from https://www.npmjs.com/package/node-localstorage. But, when I test my extension with the given code in the link above, I get an error:
Message: Module `localStorage.js` is not found at resource://gre/modules/commonjs/localStorage.js
Stack:
module.exports@resource://xxx-at-xyz-dot-com/scripts/Somescript.js:3:23
@resource://xxx-at-xyz-dot-com/index.js:6:11
run@resource://gre/modules/commonjs/sdk/addon/runner.js:147:19
startup/</<@resource://gre/modules/commonjs/sdk/addon/runner.js:87:9
Handler.prototype.process@resource://gre/modules/Promise-backend.js:933:23
this.PromiseWalker.walkerLoop@resource://gre/modules/Promise-backend.js:812:7
this.PromiseWalker.scheduleWalkerLoop/<@resource://gre/modules/Promise-backend.j s:746:1 –
Here is an approximation of how I was trying to use localStorage:
//Somescript.js (background script)
module.exports = function () {
this.watchTab = function (tabId, port, url) {
//some code
localStorage.setItem("key","value");
// some code
}
}
The line localStorage.setItem("key","value")
throws an error ReferenceError: localStorage is not defined.
This is the reason I am not able to use localStorage.