【问题标题】:Manipulating SQLite database from Firefox Addon worker从 Firefox Addon worker 操作 SQLite 数据库
【发布时间】:2013-04-16 12:56:44
【问题描述】:

我正在开发一个 Firefox 扩展,它需要经常写入 SQLite 数据库(这是出于一些实验目的,而不是生产或任何东西)。问题是写入数据库有相当多的开销,所以我认为我可以将这部分移动到后台工作人员,以免中断浏览活动。

现在我的问题是我无法从工作人员访问 XPCOM 组件;即做

Components.utils.import("resource://gre/modules/Services.jsm");
Components.utils.import("resource://gre/modules/FileUtils.jsm");

来自工作人员将无法工作 (Components undefined)。

有什么解决方法吗?

【问题讨论】:

  • 您是如何创建员工的?如果这些是页面工作者,您将无权访问 Components 对象。
  • @BryanClark 我使用ChromeWorkers

标签: sqlite firefox-addon-sdk xpcom worker


【解决方案1】:

查看 indexed-db 模块https://addons.mozilla.org/en-US/developers/docs/sdk/latest/modules/sdk/indexed-db.html

var { indexedDB } = require('indexed-db');

var request = indexedDB.open('MyDatabase');
request.onerror = function(event) {
  console.log("failure");
};
request.onsuccess = function(event) {
  console.log("success");
};

【讨论】:

  • 如果我看看here,这个解决方案似乎与工人不兼容。
  • 你必须从worker向主线程发送消息,indesDB的东西无论如何都是异步的......
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-01-10
  • 2017-03-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多