I keep receiving a QUOTA_BYTES_PER_ITEM error when attempting to store an object, even though my size precheck shows that it should be under the quota. I must be missing something simple here (is this method correct for checking object size?). I've already compressed the item using LZString, yet it still appears smaller than the allowed 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);
}
});