So I am writing a browser pluging for Firefox and need to get to the javascript environment of the current tab the user was looking at. Here is the code that allows that to happen.
var mainWindow = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor) .getInterface(Components.interfaces.nsIWebNavigation) .QueryInterface(Components.interfaces.nsIDocShellTreeItem) .rootTreeItem .QueryInterface(Components.interfaces.nsIInterfaceRequestor) .getInterface(Components.interfaces.nsIDOMWindow);
var current_doc = mainWindow.gBrowser.contentWindow.wrappedJSObject;
if (typeof(current_doc.menu_items) != "undefined") { build_menu(current_doc.menu_items);
}
Notice I check if the variable I want exist or not. This is because in my case it is possible that the page being show does not have the variable I was interested in.
Also I removed a bunch of name-spacing in order to make it more readable.
