简体   繁体   中英

Edge extendsion chrome.storage.local 1MB limit

Porting an existing extension from chrome to edge and I'm having issues with the 1mb limit on chrome.storage.local. I used the function in this topic String length in bytes in JavaScript to find he size of the string and found if the json string is over 1mB it will throw a "over 1mB" exception, but if the json string was between 250kB and 1mB I get a message in chrome.runtime.lastError saying the data is over 1mB, no exception is thrown and the data is not stored.

I tried switching to browser.storage but I'm getting the same results. Is this a bug or is the byte size function I'm using wrong?

Also I'm using lz-string to compress the data to try and increase my storage.

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

}

According to the Extension API Roadmap ( https://docs.microsoft.com/en-us/microsoft-edge/extensions/api-support/extension-api-roadmap ), Microsoft Edge supports the unlimitedStorage permission in builds 14986 and above (currently only available to Windows Insiders, though it will be available publicly once the Windows 10 Creators Update launches). Using this should let you get around the 1MB size limitations, but since Edge's namespace is browser , you'll have to change the above code to browser.storage.local

If you need to sign up for the Windows Insider Preview program, you can do so here: https://insider.windows.com

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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