8

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?

4

1 回答 1

19

根据chrome.storageAPI,存储值的正确方法是.set

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

稍后要访问该值,请.get与接受数据的回调一起使用:

chrome.storage.local.get("mykey", function(fetchedData) {
    alert("fetched: " + fetchedData.mykey);
});
于 2012-08-16T13:28:53.800 回答