Chrome.storage.local ["mykey"] - undefined

I am doing a Chrome extension where I will store the user password in local storage. I save it in popup.js with

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

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

+4
source share
1 answer

According to the chrome.storage API, the correct way to store the value is .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); }); 
+11
source

All Articles