将现有的扩展从chrome移植到边缘,并且遇到chrome.storage.local的1mb限制问题。我使用了这个主题String length in bytes in JavaScript中的函数来查找字符串的大小,并发现如果json字符串超过1mB,它将抛出一个“超过1mB”的异常,但是如果json字符串在250kB和1mB之间,我会在chrome中得到一条消息.runtime.lastError表示数据超过1mB,不会抛出异常并且不存储数据。边缘扩展chrome.storage.local 1MB限制
我试着切换到browser.storage,但我得到了相同的结果。这是一个错误还是我使用的字节大小函数是错误的?
此外,我正在使用lz字符串来压缩数据以尝试增加我的存储空间。
tmp = JSON.stringify(tmp);
tmpAsString = LZString.compressToUTF16(tmp);
var compresskey = 'compressedJSExtension';
try {
chrome.storage.local.set({[compresskey] : tmp }, function() {
if (chrome.runtime.lastError) console.error(chrome.runtime.lastError);
});
}
catch (f) {
//Handle if the string is over 1mB
}