Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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"
    ]
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
423 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...