Search code examples
sqlitefirefox-addon-sdk

Firefox extension development sqlite


using Builder online tool https://builder.addons.mozilla.org/ to build and test my extension now that I want to store data locally I'm following this tutorial https://developer.mozilla.org/en/Storage but the code snippets are not working for me Should I be developing them locally using the classic SDK or is there a way to add SQLite support to the Add-on builder ?


Solution

  • Add-on SDK is sandboxed by default and doesn't provide direct access to XPCOM. To use XPCOM objects you need to 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);
    

    Note that Components stays undefined - use Cc instead of Components.classes, Ci instead of Components.interfaces and Cu instead of Components.utils.