使用 .crx 将预定义数据发送到浏览器本地存储

发布于 2024-12-23 10:33:28 字数 500 浏览 4 评论 0原文

我正在构建我的第一个 Chrome 扩展,因为我想在客户端浏览器上有一些预定义的数据。

我希望用户能够通过扩展来编辑数据并保存更改。

我首先想到使用 HTML5 本地数据库Indexed Database API 来实现此目的。(我做得对吗?)

但我不知道如何将此本地数据库发送到客户端放在 .crx 中......因为数据库将与浏览器而不是扩展程序一起使用。

如何通过.crx将数据发送到客户端浏览器并将数据保存在浏览器上? (我知道在浏览器上保存数据是不对的,但是如果我将数据与扩展名一起保存,则无法将数据保存回来)

我还可以使用其他什么方式来实现该要求?

如果我想使用Indexed Database API,我可以使用相同的方法吗?


我的数据不是简单的键值对,而是表类型的数据。
我没有任何数据访问部分的代码,因为我想在继续之前确定一下

I am building my first chrome extension, for that I want to have some predefined data at client browser.

I want that data be able to be edited by user by means of extension and save back the changes.

I first thought of using HTML5 local database or Indexed Database APIfor this.(Am I doing right?)

But I don't know how can I send this local database to client place in .crx..because the database will be with browser rather than extension.

How can I send data to client side browser by .crx and save the data on browser?
(I know its not right to save data on browser, but I can't save data back if I save data along with extension)

What other way I can use to implement the requirement?

can I use the same method if I want to use Indexed Database API instead?


My data is not simple key value pair but table kind of data.
I don't have any code for data access part, because I want to be sure before I can proceed

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

扶醉桌前 2024-12-30 10:33:28

不,您不能使用 ctx 文件发送数据库文件。简单地说,您无法在客户端替换它。
实际上,您有两个选择:

1)将预定义数据保存到您的扩展中(在任何扩展文件中。将整个查询或数据保存为 JSON),并在首次运行后将这些查询执行到本地数据库。

2) 创建 Web 服务,从中获取预定义数据并将其保存到本地数据库。

例如(data.json):

[{"name":"name", "desc":"desc","some_column":"some value"},{"name":"name", "desc":"desc","some_column":"some value"}, ...]

在background.html中:

var xhr = new XMLHttpRequest();
xhr.open('GET', chrome.extension.getURL('data.json'), false);
var dataStr = xhr.send(); //don't do this way. use asynch api :)
var data = JSON.parse(dataStr);
//connect to local database
for(var _item in data){
    //create query to insert data into DB
    //and exequte query
}

No, You can't send database file with ctx file. Simply You can't replace it on client side.
Actually you have two options:

1) save predefined data into your extension (in any extension file. save whole query or data as JSON) and after first run exec those query to local Database.

2) create web service from where you will get predefined data and save it to local DB.

For example (data.json):

[{"name":"name", "desc":"desc","some_column":"some value"},{"name":"name", "desc":"desc","some_column":"some value"}, ...]

In background.html:

var xhr = new XMLHttpRequest();
xhr.open('GET', chrome.extension.getURL('data.json'), false);
var dataStr = xhr.send(); //don't do this way. use asynch api :)
var data = JSON.parse(dataStr);
//connect to local database
for(var _item in data){
    //create query to insert data into DB
    //and exequte query
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文