I am getting a QUOTA_BYTES_PER_ITEM quota exceeded error when trying to save an object to storage, but my precheck of the size passes. I am sure I am making some sort of basic mistake here (is this a valid way to check size of an object?). I have already compressed the item I want to save with LZString, but regardless, it seems much smaller than the quota.
var objToSave = {};
objToSave[myKey] = compressedObj;
console.log("Size of obj is: " + JSON.stringify(objToSave).length); //prints 3452
console.log(chrome.storage.sync.QUOTA_BYTES_PER_ITEM); //prints 8192
if (JSON.stringify(objToSave).length >= (chrome.storage.sync.QUOTA_BYTES_PER_ITEM)) { // this never triggers
alert('objToSave is too large!');
return;
}
chrome.storage.sync.set(objToSave, function() {
if (chrome.runtime.lastError) { // this error gets triggered.
console.log("Error: " + chrome.runtime.lastError.message); // this error gets triggered.
return customAlert("Error!: " + chrome.runtime.lastError.message);
}
});
Well, the only logical reason for you to get QUOTA_BYTES_PER_ITEM is that you are trying to use a string that exceeds that 8k mark...
However there are 2 things that I feel might be going wrong here..