For debugging purposes, I need to automatically load a large number of URLs (successively) in a given Firefox tab.
More precisely, my goal is to load URL1, URL2, etc., as if the user had typed these URLs in the URL bar and typed return, always in the same tab, and log the network traffic that is generated by these requests. Logging the network traffic is easy by using the “Network” part of the Firefox dev tools while having “Persist Logs” on: so the question is how to load the various URLs successively without having to actually to enter them manually.
I can't simply run a JavaScript loop in the web console that puts the different values in window.location.href, because loading a new URL creates a new JavaScript context so my loop is gone as soon as it is started.
Another idea would be to ask Firefox to open a URL in the current tab from the command-line, but there currently does not seem to be any way to do this (some pages suggest that running firefox -remote 'openURL("https://example.org/")' should do it, but if this command ever worked, it no longer does).
I suspect, however, that running JavaScript code from the Firefox global “Browser console” (as opposed to the web console) should allow me to open a URL in a given Firefox tab, because the browser console has control over all the browser tab. But my question is: how?
The aforementioned link would lead one to believe that the following code might work:
var newTabBrowser = gBrowser.getBrowserForTab(gBrowser.selectedTab);
newTabBrowser.contentDocument.location.href = "https://example.org/";
— however, it does not (newTabBrowser.contentDocument is null) and I have failed to guess any variation that does.
I could not find any documentation for the gBrowser object or what one can do with it (some pages suggest that this whole system of interacting with the browser is somehow obsolete, but I couldn't find any explanation as to what is supposed to replace it). So:
Question: How can one load a given URL in the current browser tab using JavaScript run from inside the Firefox “Browser console” (as if the user had entered that URL in the location bar)? Alternatively, any other suggestion on how to achieve the same goal of loading a URL in the current Firefox tab are welcome.