【问题标题】:Edge extendsion chrome.storage.local 1MB limit边缘扩展 chrome.storage.local 1MB 限制
【发布时间】: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


    【解决方案1】:

    根据扩展 API 路线图 (https://docs.microsoft.com/en-us/microsoft-edge/extensions/api-support/extension-api-roadmap),Microsoft Edge 在内部版本 14986 及更高版本中支持 unlimitedStorage 权限(目前仅适用于 Windows 预览体验成员,但一旦 Windows 10 创意者更新启动后将公开提供) .使用它应该可以让你绕过 1MB 的大小限制,但由于 Edge 的命名空间是 browser,你必须将上面的代码更改为 browser.storage.local

    如果您需要注册 Windows Insider Preview 计划,可以在此处注册:https://insider.windows.com

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-08-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-24
      相关资源
      最近更新 更多