qnsi
qnsi

Reputation: 380

Struggling with firefox addon. How do I add a panel only when run on a specific webpage?

I know I need to use page-mod and panel. But how do I run a panel from the contentscript?

var { Panel } = require("sdk/panel");
var pageMod = require("sdk/page-mod");
var data = require("sdk/self").data;

var panel = Panel({
    width: 1000,
    height: 600, 
    contentURL: "http://www.website.com"
});

pageMod.PageMod({
    include: "https://www.somewebsite.com*",
    contentScript: 'panel.show();'
}); 

This is the furthers I can get. Documenitation is unclear for me, but maybe because I am new to this. I really appreciate your help.

Upvotes: 0

Views: 80

Answers (1)

therealjeffg
therealjeffg

Reputation: 5830

The panel object isn't in the content script's scope. What you want to do instead to use the 'onAttach' handler:

var { Panel } = require("sdk/panel");
var pageMod = require("sdk/page-mod");
var data = require("sdk/self").data;

var panel = Panel({
    width: 1000,
    height: 600,
    contentURL: "http://www.website.com"
});

pageMod.PageMod({
    include: "https://www.somewebsite.com*",
    // contentScript: 'panel.show();'
    onAttach: function(worker) {
      panel.show();
    }
});

Upvotes: 1

Related Questions