1

I'm writing a Google Chrome extension. I know that Chrome currently sets the limit of 5MB on the maximum allowed size of localStorage. But I'm curious if there's any way to get this from the Chrome itself, anything like a JS constant/global variable?

PS. I just hate to hard-code this value in case they change it in the future.

c00000fd
  • 20,994
  • 29
  • 177
  • 400

2 Answers2

0

We assume that one character equals one byte, but this is not a safe assumption. Strings in JavaScript are UTF-16, so each character requires two bytes of memory. This means that while many browsers have a 5 MB limit, you can only store 2.5 M characters.

It is quite difficult to predict how much is left for the domain, even if it is set to 5 MB.

After reading through about HTML5 Storage. It is quite possible to look for unlimited storage option.

https://developers.google.com/chrome/whitepapers/storage#unlimited

In this documentation they are suggesting manifest as:

 "storage": {
    "managed_schema": "schema.json"
  },

I have not tested myself but it is worth to give it a try. If it works then please let me know as well.

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
codebased
  • 6,945
  • 9
  • 50
  • 84
0

Updated 2021: https://developer.chrome.com/docs/extensions/reference/storage/#property-local

Use chrome.storage.local.QUOTA_BYTES.

Jess Uni
  • 37
  • 1
  • 5