gpt4 book ai didi

javascript - Edge 扩展 chrome.storage.local 1MB 限制

转载 作者:行者123 更新时间:2023-12-01 03:57:02 28 4
gpt4 key购买 nike

将现有扩展从 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

}

最佳答案

根据扩展 API 路线图 ( https://learn.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 Preview 计划,可以在此处进行注册:https://insider.windows.com

关于javascript - Edge 扩展 chrome.storage.local 1MB 限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42566150/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com