5

I'm looking for an efficient way to store large amounts of data in my chrome extension. I've got a few txt files which are around 1-2mb. I'd like my chrome extension to 'cache' them locally so I don't need to fetch them every time. I've found syncFileSystem but this is only available for packed apps.

There were warnings when trying to install this extension:

'syncFileSystem' is only allowed for packaged apps, but this is a extension.

What is the best way to store this sort of data in a chrome extension?

manifest.json

{
    "manifest_version": 2,
    "name": "__MSG_name__",
    "version": "1.0",
    "default_locale": "en",
    "description": "__MSG_description__",
    "icons" : {
        "16" : "img/logo_enabled_16.png",
        "48": "img/logo_enabled_48.png",
        "128": "img/logo_enabled_128.png"
    },
    "browser_action": {
        "default_icon": "img/logo_enabled_48.png",
        "default_title": "__MSG_browser_action_title__",
        "default_popup":"options.html"
    },
    "background": {
        "scripts": [
            "js/chrome.js",
            "js/filter.js",
            "js/background.js"
        ],
        "persistent": true
    },
    "content_scripts": [{
        "matches": [
            "http://*/*",
            "https://*/*"
        ],
        "js": [
            "js/docReady.js",
            "js/content.js"
        ]
    }],
    "offline_enabled":true,
    "options_ui": {
        "chrome_style": true,
        "page":"options.html"
    },
    "permissions": [
        "activeTab",
        "tabs",
        "webRequest",
        "webRequestBlocking",
        "webNavigation",
        "storage",
        "syncFileSystem",
        "http://*/*",
        "https://*/*"
    ],
    "short_name": "__MSG_shortName",
    "minimum_chrome_version":"45.0.2454.101",
    "web_accessible_resources":[
        "css/bootstrap.min.css",
        "js/jquery.min.js",
        "js/chrome.js",
        "js/bootstrap.min.js"
    ]
}

1 Answers1

14

Only WebSQL, IndexedDB, chrome.storage.local and HTML5 File System (sandboxed file system) can grow past 5MB limit via "unlimitedStorage" permission.

manifest.json: "permissions": ["unlimitedStorage"]

Provides an unlimited quota for storing HTML5 client-side data, such as databases and local storage files. Without this permission, the extension or app is limited to 5 MB of local storage.

Notes:

  • WebSQL is deprecated by W3C in favor of the slower IndexedDB but I think it will stay in Chrome for the obvious reason that it's faster and more flexible due to being SQL-based.
  • chrome.storage.local is the easiest to use but it may not be the fastest with the large objects, do some tests if speed is important.
  • Use a Zip/LZMA Javascript library to compress/decompress the text files if the gain is significant.
wOxxOm
  • 65,848
  • 11
  • 132
  • 136
  • Somehow you completely omit `chrome.storage`. Note that `localStorage` is also available and will grow past 5 Mb. – Xan Dec 03 '15 at 09:38
  • 2
    @Xan: `localStorage` won't grow, see https://crbug.com/58985 as for `chrome.storage.local` you're right. – wOxxOm Dec 03 '15 at 10:15
  • In that bug there's an amusing label `not-extensions`. But, yes, from other places in the docs it's confirmed as not affecting `localStorage`, sorry about that. – Xan Dec 03 '15 at 10:17
  • 1
    the `unlimitedStorage` is only for apps, is there an option for extensions? – ospider Feb 26 '18 at 10:25
  • @ospider, my experience shows that extensions' storage isn't limited by default at all. [Evidently](https://cs.chromium.org/chromium/src/chrome/browser/extensions/extension_storage_monitor.h?l=119&rcl=9e25952fd786af7f983525980cdae2c5b90b0dde) this permission is required for *ephemeral apps* whatever those are. – wOxxOm Feb 26 '18 at 10:31
  • Thanks, I couldn't find any clear doc on that, I will just take your words :P – ospider Feb 26 '18 at 10:32
  • 1
    @wOxxOm wow, good find. I realized that my extension, which doesn't request the "unlimitedStorage" permission, has a storage quota [larger than 5mb](https://i.imgur.com/IR4SkNd.png) by default. I checked this on Chrome v76 – lasec0203 Aug 08 '19 at 07:32
  • @lasec0203 all extensions which I've installed and don't have unlimitedStorage permission show total of 296631 MB storage quota (chromium ms edge browser) – GorvGoyl Apr 05 '22 at 08:55