將現有的擴展從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
}