【发布时间】:2017-03-02 21:17:53
【问题描述】:
将现有扩展从 chrome 移植到 edge 时,我遇到了 chrome.storage.local 的 1mb 限制问题。我使用这个主题String length in bytes in JavaScript 中的函数来查找字符串的大小,发现如果 json 字符串超过 1mB,它将抛出“超过 1mB”异常,但如果 json 字符串在 250kB 和 1mB 之间,我会收到一条消息在 chrome.runtime.lastError 中说数据超过 1mB,没有抛出异常并且数据没有被存储。
我尝试切换到 browser.storage,但得到了相同的结果。这是一个错误还是我使用的字节大小函数有误?
我还使用 lz-string 压缩数据以尝试增加存储空间。
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
}
【问题讨论】:
标签: javascript local-storage microsoft-edge-extension