0

Is it possible to open Mozilla Firefox via Batch File, followed by opening the Network Monitor (Ctrl+Shift+Q), then navigating to a specific URL. Once complete (maybe with some timer delays inbetween each action), Firefox then closes.

The reason for this is because the Network Monitor automatically exports its contents to a file, which I want to automate on a schedule to ensure the contents of a specific URL are as expected - without having to manually check each time.

Basically this is to assist web development.

DARKOCEAN
  • 109
  • 3
  • 14
  • 2
    Doing that with pure [tag:batch-file] is (almost) impossible, I guess. What about [tag:auto-it] or [tag:autohotkey]? – aschipfl Aug 23 '16 at 16:22
  • GUI manipulation is one of only two times I will ever recommend PowerShell on a question with the [batch-file] tag. – SomethingDark Aug 23 '16 at 16:49
  • Ok, so new question, how would I achieve what I want to do? – DARKOCEAN Aug 23 '16 at 16:51
  • While difficult (at best) in a batch file, it would be trivial in a Firefox [Add-on SDK](https://developer.mozilla.org/en-US/Add-ons/SDK) extension. A specific profile could have the add-on (which opens the Network Monitor, navigates to the URL and then closes Firefox) installed. Firefox could then be executed on a schedule using that profile. – Makyen Aug 23 '16 at 18:00
  • However, as phrased, this question is off-topic. It is either asking for just a Yes/No response (which is probably not what the OP wants, thus unclear what you are asking), or is too broad (too many different ways to implement). Please [edit] the question to refine it. See: [What topics can I ask about here?](http://stackoverflow.com/help/on-topic), and [How do I ask a good question?](http://stackoverflow.com/help/how-to-ask). – Makyen Aug 23 '16 at 18:06
  • In terms of the SDK Extension, I'm guessing such an extension doesn't exist? So I would have to create it myself or ask someone to create it for me? – DARKOCEAN Aug 23 '16 at 18:14
  • @MatthewJohnSymons If you want a particular user to be notified of you leaving a comment, you need to include `@` followed by their user name in your comment. For example, for me it would be `@Makyen`. If you type `@` and the first character of the user name desired as the first characters of your comment, it will show some auto-complete options ( use the 'Tab' key to accept). As to an add-on already existing: A brief search on [AMO](https://addons.mozilla.org/en-US/firefox/), prior to my writing my first comment, did not show any already existing add-ons, so yes it would have to be written. – Makyen Aug 23 '16 at 21:43

2 Answers2

0

Assuming you want to check the content of a website or only document if it is available, you might want to take a look at wget. With that you could archive the log or the download of the file.

Florian Straub
  • 826
  • 9
  • 18
0

So, I ended up implementing a Firefox Add-on SDK extension that

  • Upon Firefox startup: Waits until after the ready event fires for the current tab
  • After a delay, Opens the Network Monitor
  • After an additional delay, Navigates to a webpage (google.com in the example code)
  • After the ready event fires for that navigation, wait an additional delay and close Firefox.

Currently the page to which to navigate is hard coded. If you need to, it would be possible to make this configurable in a few different ways.

Below is what it looks like when used on Windows 10. jpm run is from Firefox Add-on SDK development. it allows testing an SDK add-on. You will probably also want to read "jpm run does NOT work with Firefox 48, or later":

LICEcap Firefox open Network Monitor, navigate to google.com, close Firefox

package.json:

{
    "title": "Open Network Monitor, navigate, close",
    "name": "netmonitor-navigate-close",
    "version": "0.0.1",
    "description": "Opens the network Monitor, navigates to a page, then closes Firefox",
    "main": "index.js",
    "author": "Makyen",
    "engines": {
        "firefox": ">=38.0a1",
        "fennec": ">=38.0a1"
    },
    "license": "MIT",
    "keywords": [
        "jetpack"
    ]
}

index.js:

//Opens network monitor, navigates to a page, then closes Firefox.

var pageToNavigateTo = "http://www.google.com";
//Whatever the home page is might have web access happen after
//  the ready event.  Delay opening the Network monitor so those are skipped.
var delayFirstTabReadyToOpenNetworkmonitor = 3000; //In ms. 3000 = 3 seconds
var delayOpenNetworkmonitorToNavigate = 3000; //In ms. 3000 = 3 seconds
var delayUrlReadyToClose = 5000; //In ms. 5000 = 5 seconds


var tabs = require("sdk/tabs");
var utils = require('sdk/window/utils');
var activeWin = utils.getMostRecentBrowserWindow();

function getActiveWin() {
    activeWin = utils.getMostRecentBrowserWindow();
}
getActiveWin();

function openNetworkMonitor(){
    activeWin.document.getElementById('menuitem_netmonitor').doCommand();
}

function receiveFirstTabReadyEvent(tab){
    getActiveWin();
    tabs.off('ready', receiveFirstTabReadyEvent);
    activeWin.setTimeout(openNetworkMonitor,delayFirstTabReadyToOpenNetworkmonitor ,tab);
    activeWin.setTimeout(navigateToTheUrl,(delayFirstTabReadyToOpenNetworkmonitor 
                         + delayOpenNetworkmonitorToNavigate) ,tab);
}

function navigateToTheUrl(tab){
    tab.on('ready',theUrlIsReady);
    tab.url=pageToNavigateTo; //navigate
}

function theUrlIsReady(tab){
    tab.off('ready',theUrlIsReady);
    getActiveWin();
    //Some actions may take place in the page after the ready event.  Thus,
    //  wait some extra time.
    activeWin.setTimeout(exitFirefox,delayUrlReadyToClose); //Exit after delay
}

function exitFirefox(){
    getActiveWin();
    activeWin.document.getElementById('cmd_quitApplication').doCommand();
}

tabs.on('ready', receiveFirstTabReadyEvent);
Community
  • 1
  • 1
Makyen
  • 31,849
  • 12
  • 86
  • 121