Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open a tab in Mozilla Add On SDK

I am developing a Mozilla Add on. I am trying to open a tab.

According to https://addons.mozilla.org/en-US/developers/docs/sdk/1.0/packages/addon-kit/docs/tabs.html it is done using

console.log("before tab");
var tabs = require("tabs");
tabs.open("http://www.example.com");

But it is not working on my case.

I am doing that in the content script. I have a page called popup.html and a content called popup_script.js.

The code is reached because the message is logged.

Any idea?

like image 336
Tony Avatar asked Mar 29 '12 17:03

Tony


1 Answers

Content scripts don't have access to "advanced" APIs, they can merely communicate with the extension. So your content script should send a message to the extension and the extension should open the tab then. Like this:

self.port.emit("openTab", "http://www.example.com");

And in main.js:

panel.port.on("openTab", function(url)
{
  var tabs = require("tabs");
  tabs.open(url);
});
like image 128
Wladimir Palant Avatar answered Oct 13 '22 23:10

Wladimir Palant