Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

chrome.storage.local["mykey"] is undefined

I am making a Chrome extension where I will store the password from the user in local storage. I am storing it in popup.js using

chrome.storage.local["mykey"] = "xxx";

When I use chrome.storage.local["mykey"], I'm getting undefined. Can you tell me how to store and retrieve user data in a Chrome extension?

like image 271
Rocky Singh Avatar asked Aug 16 '12 11:08

Rocky Singh


1 Answers

According to the chrome.storage API, the correct way to store a value is with .set:

chrome.storage.local.set({"mykey": someData}, optionalCompletionCallback);

And to access the value later, use .get with a callback that accepts the data:

chrome.storage.local.get("mykey", function(fetchedData) {
    alert("fetched: " + fetchedData.mykey);
});
like image 99
apsillers Avatar answered Sep 20 '22 19:09

apsillers