I have a small chrome extension I've built using chrome.storage.sync api to cache user-entered data. However, when the user runs a delete operation, the data persists in the storage area, even after I run sync.remove and sync.clear- is there something I'm missing?
chrome.storage.sync.get('tasks', function(obj) {
//assign tasks array to variable
var tasks = obj.hasOwnProperty('tasks') ? obj.tasks : [];
chrome.storage.sync.remove('tasks': liValue);
chrome.storage.sync.clear();
//find and remove deleted task from array, checking against cached li text value
//liValue is cached textnode value prior to dom deletion
for(var j = 0; j < tasks.length; j++) {
if(tasks[j] == liValue) {
tasks.splice(j, 1);
alert("splicing " + tasks[j] + "!!!");
}
}
//reset tasks in storage
chrome.storage.sync.set({'tasks': tasks}, function() {
if (chrome.runtime.lastError)
console.log(chrome.runtime.lastError);
else
console.log("Tasks saved successfully");
});
});
I've looked thru the docs here and as best I can tell I'm using the method signatures correctly. Somebody described a similar issue in this SO post but applying the same code does not seem to be resolving my issue.