Chrome扩展程序存储大量数据 [英] Chrome extension store large amounts of data

查看:558
本文介绍了Chrome扩展程序存储大量数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种有效的方法来在我的Chrome扩展中存储大量数据。我有几个大约1-2mb的txt文件。
我希望我的Chrome扩展在本地缓存它们,所以我不需要每次都抓取它们。
我找到了 syncFileSystem ,但这只适用于打包应用程序。


尝试安装此扩展程序时出现警告:



'syncFileSystem'只允许对于打包的应用程序,但是这是一个
的扩展名。


什么是将这类数据存储在Chrome扩展?



manifest.json

  {
manifest_version:2,
name:__MSG_name__,
version:1.0,
default_locale:en,
description: __MSG_description__,
图标:{
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_br
default_popup:options.html
},
background:{
scripts:[
js / chrome.js ,
js / filter.js,
js / background.js
],
持久性: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,
标签,
webRequest,
webRequestBlocking,
webNavigation,
存储,
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
]
}

解决方案

只有 WebSQL IndexedDB chrome.storage.local 和HTML5 文件系统(沙盒文件系统)可以通过 unlimitedStorage权限
$ b manifest.json:permissions:[unlimitedStorage]




为存储HTML5客户端数据(如数据库和本地存储文件)提供无限配额。没有此权限,扩展程序或应用程序被限制为5 MB的本地存储空间。


注释:




  • W3C赞成使用较慢的IndexedDB,而不赞成使用WebSQL,但我认为它会留在Chrome中,原因很明显,因为它是基于SQL的,所以它更快更灵活。

  • chrome.storage.local 是最容易使用的,但它可能不是大对象中最快的,请做一些测试if速度很重要。

  • 如果收益显着,可以使用Zip / LZMA Javascript库来压缩/解压缩文本文件。


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"
    ]
}

解决方案

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.

这篇关于Chrome扩展程序存储大量数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆