Search code examples
javascriptsqlitefirefox-addonfirefox-addon-sdk

Error when make a select into sqlite from firefox add-on


I'm using the sqlite.js librarie on a firefox add-on that I'm writing.

I have inserted a lot of data whitout problems, but, when I try to make this very simple select

function selecionaUsuarioPorNome (nome, teste){
    sqlite.execute("select * from Usuario;", function(result,status){
        cm.enviaMensagem ("rows = " + result.rows + "\ncols = " + result.cows);
        for(var i=0;i<result.rows;i++){
            for(var j=0;j<result.cols;j++){
                console.log(result.data[i][j]);
            }
        }
    });
}

I got the follow error:

[17:08:29,013] [Exception... "'Error: The page is currently hidden and can no longer be used until it is visible again.' when calling method: [mozIStorageStatementCallback::handleCompletion]" nsresult: "0x8057001c (NS_ERROR_XPC_JS_THREW_JS_OBJECT)" location: "native frame :: :: :: line 0" data: no]

The structure of my projet is:

/
|
|___Lib
. . |
. . |____ main.js
. . |____ bd_manager.js
. . |____ sqlite.js

And in the main.js I put the main function:

exports.main = function (options, callbacks) {
    // quando o add-on é instalado
    if (options.loadReason == "install"){
        // call to test if I can get the user from the database.sqlite
        bd.selecionaUsuarioPorNome ("vitor", function (){});
    }
}

Someone knows this error?

Thank you very much!


Solution

  • Doesn't seem to have anything to do with SQLite. The error is generated when you try to send a message to a content script (worker) that is attached to a page which isn't loaded anymore, but still in the back-forward cache (bfcache). So the worker you try to send a message to is attached to a page the user or your add-on navigated away from already.

    Your callback, which is executed from the handleCompletion wrapper in sqlite.js, triggers this error. Likely the following line, as the other lines seem OK and this one is the only one without source code for it.

    cm.enviaMensagem ("rows = " + result.rows + "\ncols = " + result.cows);`
    

    Without knowing more of your code (a full, reproducible example), I cannot tell you more than this.