vava
vava

Reputation: 25391

How to get tab in TabOpen event with Firefox FUEL?

I'm writing a firefox extension and really need to listen on TabOpen events and get some details about tab that was opened. But I can't figure out how do I get an actual tab from event object that my callback receives. Is it somewhere in event.data? Is there a way to inspect this object?

Some code that I have tried so far but it doesn't work:

Application.activeWindow.events.addListener("TabOpen",
    function(event) {
        Application.console.log("TabOpen");
        var tab = event.data.target;
        Application.console.log(tab.uri);
    }
);

Upvotes: 2

Views: 1472

Answers (3)

Reputation:

I've added some new content to MDC that should help with this; information on how to pull the tab object out of the TabOpen event is now available in the example here:

https://developer.mozilla.org/En/FUEL/Window

Also did some other cleaning up while I was at it. Hopefully this will help (especially once the search index refreshes).

Upvotes: 0

sdwilsh
sdwilsh

Reputation: 4682

In your code, event.data will give you a BrowserTab object. If you want the current URI of the tab, you'd want tab.uri.spec for the string version, or just tab.uri if you want an nsIURI object.

Upvotes: 1

user434917
user434917

Reputation:

here is an example from the MDC but without using FUEL:

// add event listener
var container = gBrowser.mPanelContainer;
container.addEventListener("DOMNodeInserted", exampleTabAdded, false);

function exampleTabAdded(event)
{ // listening for new tabs
  if (event.relatedNode != gBrowser.mPanelContainer)
    return; //Could be anywhere in the DOM (unless bubbling is caught at the interface?)

  var browser;
    browser = event.target.childNodes[1];
  // browser is the XUL element of the browser that's been added
}

Upvotes: 0

Related Questions