Get current page URL from a firefox sidebar extension

I stumbled over this post while looking for an answer to the same question.

Actually I think it's as easy as

alert(window.content.location.href)

See also https://developer.mozilla.org/en/DOM/window.content


window.top.getBrowser().selectedBrowser.contentWindow.location.href;

might work, otherwise I think you need to use:

var mainWindow = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                   .getInterface(Components.interfaces.nsIWebNavigation)
                   .QueryInterface(Components.interfaces.nsIDocShellTreeItem)
                   .rootTreeItem
                   .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                   .getInterface(Components.interfaces.nsIDOMWindow);

mainWindow.getBrowser().selectedBrowser.contentWindow.location.href;