1

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.

1 Answer 1

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; }); 
Sign up to request clarification or add additional context in comments.

4 Comments

BIG RED SCARY WARNING: Assigning the result to a variable within an async callback and hoping it would work may lead to problems.
@Xan not the case here thou
No, but someone using this code could use the warning.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.