繁体   English   中英

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

[英]Edge extendsion chrome.storage.local 1MB limit

将现有的扩展程序从chrome移植到边缘,我在chrome.storage.local的1mb限制上遇到了问题。 我在本主题中使用的函数在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

}

根据扩展API路线图( https://docs.microsoft.com/zh-cn/microsoft-edge/extensions/api-support/extension-api-roadmap),Microsoft Edge支持内部版本14986及更高版本中的unlimitedStorage权限(目前仅适用于Windows Insiders,尽管Windows 10 Creators Update启动后将公开提供)。 使用它应该可以避免1MB的大小限制,但是由于Edge的名称空间是browser ,因此您必须将以上代码更改为browser.storage.local

如果您需要注册Windows Insider Preview程序,可以在这里进行注册: https : //insider.windows.com

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM