javascript - How do you retrieve this value from chrome.storage? - Stack Overflow

I'm a real noob to JavascriptJSON, so this might be really obvious. I'm storing values to ch

I'm a real noob to Javascript/JSON, so this might be really obvious. I'm storing values to chrome.storage in a chrome extension JS file:

chrome.storage.sync.set({'username' : username}, function() {
    console.log('Saved',username);
}); 
chrome.storage.sync.set({'password' : password}, function() {
    console.log('Saved', username);
});

I know it's passed correctly because the console.log returns the right values.

Then I try to retrieve it in my content script, but it only returns [object Object].

chrome.storage.sync.get("username", function (username) {
    console.log("Passed successfully: Username "+username);
    studentUsername = username;
});

chrome.storage.sync.get('password', function (password) {
    console.log("Passed successfully: Password "+password);
    studentUsername = username;
});

I'm not sure why it's doing this.

I'm a real noob to Javascript/JSON, so this might be really obvious. I'm storing values to chrome.storage in a chrome extension JS file:

chrome.storage.sync.set({'username' : username}, function() {
    console.log('Saved',username);
}); 
chrome.storage.sync.set({'password' : password}, function() {
    console.log('Saved', username);
});

I know it's passed correctly because the console.log returns the right values.

Then I try to retrieve it in my content script, but it only returns [object Object].

chrome.storage.sync.get("username", function (username) {
    console.log("Passed successfully: Username "+username);
    studentUsername = username;
});

chrome.storage.sync.get('password', function (password) {
    console.log("Passed successfully: Password "+password);
    studentUsername = username;
});

I'm not sure why it's doing this.

Share Improve this question edited Nov 26, 2015 at 1:21 Teepeemm 4,5185 gold badges37 silver badges60 bronze badges asked Nov 25, 2015 at 23:53 The-ArkanianThe-Arkanian 612 silver badges5 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

Yes, it always returns an object. You'll have to access the property from the object.

chrome.storage.sync.get("username", function (obj) {  
    console.log("Passed successfully: Username "+obj.username)
    studentUsername = obj.username; 
});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745361499a4624382.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信