I am attempting to perform an action before a specific URL is loaded in the <browser>
element, whether it appears in a sidebar or tab.
For instance: (in the context of the browser's main window):
// This could also be the browser within a tab
var browser = document.getElementById("sidebar"); // <xul:browser>
// Execute a function when the browser's window is prepared for loading new content but before any scripts are executed
execOnWindowPrepared(browser, function(window) {
// Inject something, for example
window.foo = "bar";
});
// Load a URI
browser.loadURI("chrome://foo/content/bar.xul"); // (could also be http:)
Please note that I cannot execute my action immediately after the loadURI
statement as browser.contentWindow
will still reference the old window.
Maybe utilizing progress listeners could help with this, but I am unsure about which flags I should await.