2017-03-02 733 views
0

将现有的扩展从chrome移植到边缘,并且遇到chrome.storage.local的1mb限制问题。我使用了这个主题String length in bytes in JavaScript中的函数来查找字符串的大小,并发现如果json字符串超过1mB,它将抛出一个“超过1mB”的异常,但是如果json字符串在250kB和1mB之间,我会在chrome中得到一条消息.runtime.lastError表示数据超过1mB,不会抛出异常并且不存储数据。边缘扩展chrome.storage.local 1MB限制

我试着切换到browser.storage,但我得到了相同的结果。这是一个错误还是我使用的字节大小函数是错误的?

此外,我正在使用lz字符串来压缩数据以尝试增加我的存储空间。

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 

} 

回答

2

按照扩展API路线图(https://docs.microsoft.com/en-us/microsoft-edge/extensions/api-support/extension-api-roadmap),微软边缘支持unlimitedStorage许可,建立14986及以上(目前仅可用于Windows业内人士介绍,虽然这将是可公开一次在Windows 10创作者更新推出) 。使用这应该让你周围的1MB大小的限制,但由于边缘的命名空间是browser,你必须在上面的代码更改为browser.storage.local

如果您需要注册为Windows内幕预览程序,你可以做所以在这里:https://insider.windows.com