Getting the gBrowser object in Firefox
Okies finally I have succumb and decided to do a Firefox add-on or extension to save open tabs that have documents/images inside, cause I am lazy to go one by one and save them.
So first step, try and get the tab browsers elements in the browser. In Firefox, there is a gBrowser object that if you can get it will help you to get all the browser tabs and their uris.
For the documentation, the only way that you can use gBrowser directly is that if you are under the scope of browser.xul when you are doing overlays. So for other windows like dialogs and sidebars, you will need to use window.opener.getBrowser method to get to the gBrowser object. If you look at the documentation for the window object, there is no mention of the getBrowser method, seems like the docs need some updating.
Look at the Getting access to the browser in the Tabbed Browser section of the MDC, you will find the various different methods for getting a gBrowser object.
Explore posts in the same categories: ProgrammingTags: firefox
You can comment below, or link to this permanent URL from your own site.
March 16, 2010 at 8:29 pm
I had problem “gBrowser is not defined” when tried access to gBrowser from sidebar.
Solution:
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 gBrowser = mainWindow.gBrowser;
January 3, 2011 at 9:38 am
[...] Getting the gBrowser object in Firefox August 2009 1 comment Possibly related posts: (automatically generated)#1 Page and Top 3 Posts In 2009 Explore posts in the same categories: Uncategorized [...]