I am trying to save a list of dictionary objects in the chrome storage. But the following code seems to not work as expected.
When the extension loads for the first time and there is no goal
object in the storage, runtime.lasterror
object should be set and the code in that part should get executed. But it isn't.
When I uncomment the chrome.storage.sync.set
line and save the object and the next time I call the function expecting it to save a list, it doesn't. It does not give any of the alert boxes.
function isPgUrl(pg_url,gl_name) {
if(pg_url && gl_name) {
dic_url={
"name":gl_name,
"pg_url":pg_url
}
//chrome.storage.sync.set({"goal":[dic_url]});
chrome.storage.sync.get(["goal"], function(data) {
if(chrome.runtime.lastError) {
chrome.storage.sync.set({"goal":[dic_url]},function() {
alert("blah");
});
alert("here");
return;
}
var list=data.goal;
list.append(dic_url);
alert(list);
chrome.storage.sync.set({"goal":list},function() {
alert("lalala");
return;
});
});
}
}