Reputation: 15420
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?
Upvotes: 8
Views: 7172
Reputation: 115920
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);
});
Upvotes: 19