Michael
Michael

Reputation: 460

Firefox Addon SDK call js functions

I've got an addon with a working callback construct:

lib/main.js:

function myLogin(loginname,loginfield) {
    var pageUrl = tabs.activeTab.url;
    var data = require("sdk/self").data;
    var worker=tabs.activeTab.attach({
      contentScriptFile: data.url("content.js"),
      onAttach: function(worker) {
            console.log("pageMod.onAttach");
      }
    });
    worker.port.emit("doLogin", loginfield);

}

data/content.js:

self.port.on("doLogin", function(loginfield) {
    document.getElementById(loginfield).value="moo";
    document.getElementById(loginfield).focus();
    showSignInCaptcha();
});

I've got that all triggered by a button click in a sidebar.html which is not described here, I'll end up calling myLogin(). loginfield is a field on a website that is open in a tab. showSignInCaptcha() is a Javascript routine that is provided by the website open in the tab.

What is working / not working:

How can I make that function call work?

Upvotes: 4

Views: 81

Answers (1)

Michael
Michael

Reputation: 460

Figured it out:

        unsafeWindow.showSignInCaptcha();

does the job. Found that in the SDK docs: Access objects defined by page scripts

Upvotes: 2

Related Questions