Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storage Quota for Chrome.Storage.Sync?

My extension is going to be saving data like this in a string using Chrome.Storage.Sync.Set, which I will then interpret with regex/something similar:

<ID>TEXTBOX</ID><STYLE>BORDER:1PX SOLID BLACK; BACKGROUND-COLOR:YELLOW;
FONT-SIZE:18PX; FONT-FAMILY:ARIAL</STYLE><OTHER></OTHER>

I'm hoping to put all saved data in one storage item. ie:

<ID>TEXTBOX</ID><STYLE>BORDER:1PX SOLID BLACK; BACKGROUND-COLOR:YELLOW;
FONT-SIZE:18PX; FONT-FAMILY:ARIAL</STYLE><OTHER></OTHER>
<ID>TEXTBOX</ID><STYLE>BORDER:1PX SOLID BLACK; BACKGROUND-COLOR:YELLOW;
FONT-SIZE:18PX; FONT-FAMILY:ARIAL</STYLE><OTHER></OTHER>
<ID>TEXTBOX</ID><STYLE>BORDER:1PX SOLID BLACK; BACKGROUND-COLOR:YELLOW;
FONT-SIZE:18PX; FONT-FAMILY:ARIAL</STYLE><OTHER></OTHER>
<ID>TEXTBOX</ID><STYLE>BORDER:1PX SOLID BLACK; BACKGROUND-COLOR:YELLOW;
FONT-SIZE:18PX; FONT-FAMILY:ARIAL</STYLE><OTHER></OTHER>

This page here says for each "individual item in sync storage, as measured by the JSON stringification of its value plus its key length.", the size limit is 8,192 bytes. From anyone's knowledge, am I likely to go over the limit? Say if I had 40 IDs..

like image 877
Wickey312 Avatar asked Dec 09 '22 03:12

Wickey312


1 Answers

Yes. Yes, you are likely to go over the limit. Your current example, with 4 IDs, is approximately half a kilobyte. So you'll run out with 64 already.

Then your set operation will fail, and in your callback chrome.runtime.lastError will be set:

chrome.storage.sync.set(data, function() {
  if(chrome.runtime.lastError) {
    // Uh-oh..
  }
});

Do note:

  • If you don't really need to sync all this data across devices, use chrome.storage.local. It has a much more generous quota of 5,242,880 bytes..
  • ..which is removed if you ask for "unlimitedStorage" permission.
  • As Google documentation puts it, in a somewhat tongue-in-cheek fashion:

    chrome.storage is not a big truck. It's a series of tubes. And if you don't understand, those tubes can be filled, and if they are filled when you put your message in, it gets in line, and it's going to be delayed by anyone that puts into that tube enormous amounts of material.

    Sync storage requires support from Google's infrastructure - and they are not willing to give it out for free in unlimited amounts.

  • It's quite ineffective to put all this data in the storage. Analyze it, and store the analysis results - you get a cleaner data in storage.

P.S. HTML is not a regular language.

like image 96
Xan Avatar answered Dec 28 '22 23:12

Xan