使用Builder在线工具
https://builder.addons.mozilla.org/
构建和测试我的扩展
现在我想在本地存储数据,我正在学习本教程
https://developer.mozilla.org/en/Storage
但代码片段对我不起作用
我应该使用经典 SDK 在本地开发它们,还是有办法向 Add-on builder 添加 SQLite 支持?
最佳答案
默认情况下,附加 SDK 是沙盒化的,不提供对 XPCOM 的直接访问。要使用 XPCOM 对象,您需要 break out of the sandbox :
var {Cc, Ci, Cu} = require("chrome");
var {Services} = Cu.import("resource://gre/modules/Services.jsm");
var {FileUtils} = Cu.import("resource://gre/modules/FileUtils.jsm");
var file = FileUtils.getFile("ProfD", ["my_db_file_name.sqlite"]);
var mDBConn = Services.storage.openDatabase(file);
请注意
Components
保持未定义 - 使用 Cc
而不是 Components.classes
, Ci
而不是 Components.interfaces
和 Cu
而不是 Components.utils
.
关于sqlite - 火狐扩展开发sqlite,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7992544/