Trying To Save And Fetch A Javascript Object Using Chrome.storage Api?
I'm building my first chrome extension and I want it to track the TV series I watch and I'm currently trying to get it to save metadata on the series that I am following. I have a
Solution 1:
Your problem is in the callback :
When you are trying to get response.aID.anTitle
, your actually looking for the string set in response.aID.anTitle
i.e `"my Awesome Soap".
What you want is to get "anTitle"
key of the saved object.
One way is to only get the whole storageArea object and just log your wanted keys :
chrome.storage.sync.set(response.aID, function(){
chrome.storage.sync.get(function(val){
bkg.console.log("The saved title is: ", val.anTitle);
bkg.console.log("The saved newEp is: ", val.anNewEp);
bkg.console.log("The saved newEpURL is: ", val.anNewEpURL);
bkg.console.log("The saved imageURL is: ", val.anImage);
});
or if you really want to make so much call to get()
:
chrome.storage.sync.set(response.aID, function(){
chrome.storage.sync.get('anTitle', function(val){
bkg.console.log("The saved title is: ", val);
});
chrome.storage.sync.get('anNewEp', function(val){
bkg.console.log("The saved newEp is: ", val);
});
chrome.storage.sync.get('anNewEpURL', function(val){
bkg.console.log("The saved newEpURL is: ", val);
});
chrome.storage.sync.get('anImage', function(val){
bkg.console.log("The saved imageURL is: ", val);
});
});
But this one will return an object, containing only your key and its value, so if you need the value you've got to i.e console.log(val.anTitle)
Post a Comment for "Trying To Save And Fetch A Javascript Object Using Chrome.storage Api?"