通过批处理文件控制Mozilla Firefox

时间:2016-08-23 15:39:21

标签: batch-file firefox firefox-addon mozilla

是否可以通过批处理文件打开Mozilla Firefox,然后打开网络监视器(Ctrl + Shift + Q),然后导航到特定的URL。一旦完成(可能在每个动作之间有一些计时器延迟),Firefox就会关闭。

原因是因为网络监视器自动将其内容导出到一个文件,我希望按计划自动执行该文件,以确保特定URL的内容符合预期 - 无需每次都手动检查。

基本上这是为了协助网站开发。

2 个答案:

答案 0 :(得分:0)

假设您要检查网站的内容或仅检查文档是否可用,您可能需要查看wget。有了它,您可以存档日志或文件下载。

答案 1 :(得分:0)

所以,我最终实现了一个Firefox Add-on SDK扩展

  • 在Firefox启动时:等待ready事件触发当前选项卡
  • 延迟后,打开网络监视器
  • 再延迟一段时间后,导航到网页(示例代码中为google.com
  • 在就绪事件触发该导航后,请等待一段时间并关闭Firefox。

目前,要导航的页面是硬编码的。如果需要,可以通过几种不同的方式对其进行配置。

以下是在Windows 10上使用时的样子。jpm run来自Firefox Add-on SDK开发。它允许测试SDK附加组件。您可能还想阅读“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);