I have written a Chrome extension. I cannot use
localStorage.setItem
and localStorage.getItem
for storing and retrieving because background and browser action runs in different environment [as seen here].
So I decided to use the Chrome storage API:
var storage = chrome.storage.local;
var myTestVar = 'somevar';
var obj = {};
obj[myTestVar] = $("#somevar").val();
storage.set(obj);
which produced the following error:
Uncaught TypeError: Cannot read property 'local' of undefined
What am I doing wrong?
Make sure that all necessary permissions have been declared in the manifest file.
"storage"
, in your case.In general, the following steps should fix the problem of apparently undefined Chrome APIs:
chrome.storage
#manifest).chrome.storage
API can also be used in content script though)