边缘扩展chrome.storage.local 1MB限制

时间:2017-03-02 21:17:54

标签: javascript local-storage microsoft-edge-extension

将现有扩展程序从chrome移植到边缘,并且我在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

}

1 个答案:

答案 0 :(得分:2)

根据Extension API路线图(https://docs.microsoft.com/en-us/microsoft-edge/extensions/api-support/extension-api-roadmap),Microsoft Edge支持版本14986及更高版本中的unlimitedStorage权限(目前仅适用于Windows Insiders,但在Windows 10中可以公开使用创作者更新启动)。使用此功能可以让您绕过1MB的大小限制,但由于Edge的名称空间为browser,您必须将上述代码更改为browser.storage.local

如果您需要注册Windows Insider预览计划,可以在此处执行此操作:https://insider.windows.com

相关问题