Reputation: 61
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.
Upvotes: 1
Views: 4123
Reputation: 7243
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;
});
Upvotes: 6