2016-08-23 72 views
0

是否可以通過批處理文件打開Mozilla Firefox,然後打開網絡監視器(Ctrl + Shift + Q),然後導航到特定的URL。一旦完成(也許在每個動作之間有一些定時器延遲),Firefox就會關閉。通過批處理文件控制Mozilla Firefox

原因是因爲網絡監視器會自動將其內容導出到一個文件,我想按計劃自動執行該文件,以確保特定URL的內容符合預期,而無需每次都手動檢查。

基本上這是爲了協助網站的發展。

+2

這樣做,與純[標籤:批處理文件](幾乎)是不可能的,我猜。那麼[tag:auto-it]還是[tag:autohotkey]呢? – aschipfl

+0

圖形用戶界面操作是我曾經推薦過PowerShell的兩次,其中一個是[批處理文件]標記問題。 – SomethingDark

+0

好的,這麼新的問題,我將如何實現我想要做的事情? – DARKOCEAN

回答

0

假設你想檢查一個網站的內容或只有文件是否可用,你可能想看看wget。有了這個,你可以存檔日誌或文件的下載。

0

所以,我最終實現一個Firefox插件SDK擴展

  • 在Firefox的啓動:等待直到當前選項卡
  • 的延遲後,ready事件觸發後,打開網絡監視器
  • 額外的延遲之後,導航到的網頁(google.com在示例代碼)
  • 該導航就緒事件觸發後,等待額外的延遲和關閉Firefox。

當前要導航的頁面是硬編碼的。如果需要,可以通過幾種不同的方式進行配置。

以下是在Windows 10上使用時的樣子。jpm run來自Firefox附加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); 
+0

這太不可思議了。謝謝! – DARKOCEAN