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 content script that returns the title, the newest episode (and the URL of this episode) as well as the URL of the cover image of the series. I am currently trying to save it with some code on my background script (I have made sure to include "storage" under the permissions section of the manifest file).
Since my app needs to be able to track more than one series, I made an object constructor that stores the metadata I fetch using an object:
function Series(nTitle, nNewEp, nNewEpURL, nImage) {
this.anTitle = nTitle;
this.anNewEp = nNewEp;
this.anNewEpURL = nNewEpURL;
this.anImage = nImage;
}
I then attempt to save this data via the following code:
var bkg = chrome.extension.getBackgroundPage();
response.aID = new Series(response.aTitle,response.aNewEp,response.aNewEpURL,response.aImage);
chrome.storage.sync.set(response.aID, function(){
chrome.storage.sync.get(response.aID.anTitle, function(val){
bkg.console.log("The saved title is: ", val);
});
chrome.storage.sync.get(response.aID.anNewEp, function(val){
bkg.console.log("The saved newEp is: ", val);
});
chrome.storage.sync.get(response.aID.anNewEpURL, function(val){
bkg.console.log("The saved newEpURL is: ", val);
});
chrome.storage.sync.get(response.aID.anImage, function(val){
bkg.console.log("The saved imageURL is: ", val);
});
});
My callback function was designed to check the process and print out the values that I saved. However I have noticed that every value I return is simply an empty JQuery wrapper. I have tried using val[0] instead of val, but that returns "undefined". That makes me think that I am not saving my object properly or that Chrome does not recognise response.aID
as an object. So my question is how can I make something like this work?