如何为Firebug创建扩展

时间:2011-07-10 00:41:18

标签: javascript firefox-addon firebug

我需要扩展firebug以使用从网页中提取的链接(当从页面中的任何链接开始下载时)将其发送到将下载它的另一台机器。我打算用firebug为我提取这个链接。如果有任何其他方式,我可以从浏览器获取此信息,即使这将是赞赏。

2 个答案:

答案 0 :(得分:2)

以上回答观察员服务电话中的错字应为:Components.classes["@mozilla.org/observer-service;1"] .getService(Components.interfaces.nsIObserverService);

观察员服务使用的参考:https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIObserverService

答案 1 :(得分:0)

实际上,使用事件检测诸如http请求之类的东西是个坏主意,firefox xul语言的强大功能使您能够检测所有浏览器请求/响应,然后您可以从请求/响应头中确定所需的链接:  
你可以使用“http-observe”女巫实际上Firebug用于网络面板  
- 这是mozilla MDN中“http-observe”的链接[https://developer.mozilla.org/en/Setting_HTTP_request_headers][1]  
- 这里也是“http-observe”的一个简单例子

// first create observerService component as a property into your extension javascript object
    var myExtension = {   observerService:Components.classes["@mozilla.org/observerservice;1"].getService(Components.interfaces.nsIObserverService),
        init:function(){
            // in the init function setup the observe service and set witch javascript object is the listener for http response for example "this"
            this.observerService.addObserver(this,"http-on-examine-response", false);
            this.observerService.addObserver(this,"http-on-examine-cached-response", false);
        },
        observe: function(aSubject, aTopic, aData){ // the observe function
            if (aTopic == "http-on-examine-response" || aTopic == "http-on-examine-cached-response"){
                var httpChannel = aSubject.QueryInterface(Components.interfaces.nsIHttpChannel);
                var URI = httpChannel.originalURI.spec;                    
                if (aSubject.loadFlags & httpChannel.LOAD_INITIAL_DOCUMENT_URI){ // this detect if the response is primery request 
                    var contentType = httpChannel.getResponseHeader("content-type"); // check the heder content-type 
                    if (contentType == "what ever you want"){ // you can check if it zip/html/xml ...etc
                //do what ever you want
                }
                }
            }
        }   
    }