2015-11-01 24 views
0

我试着使用JPM和一个文本编辑器编写一个真正simpe插件,但是我碰到这个问题:火狐附加组件(观察员)HTTP上 - 修改 - 请求不被触发

我得到这个代码观察HTTP请求头:

var {Cc, Ci} = require("chrome"); 

console.log("inside test"); 

var httpRequestObserver = { 
    observer: function(subject, topic, data){ 

    console.log("inside observer definition"); 
    if(topic == "http-on-modify-request") { 
     var httpChannel = subject.QueryInterface(Ci.nsIHttpChannel); 

     console.log("done what i should do"); 
    } 
    }, 

    get observerService(){ 
    console.log("registered"); 
    return Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService); 
    }, 

    register: function(){ 
    console.log("registering"); 
    this.observerService.addObserver(httpRequestObserver, "http-on-modify-request", false); 
    }, 

    unregister: function(){ 
    console.log("unregistering"); 
    this.observerService.removeObserver(httpRequestObserver, "http-on-modify-request"); 
    } 
}; 

exports.httpRequestObserver = httpRequestObserver; 

,并从另一个.js文件运行此文件是这样的:

require("./theothercode.js").httpRequestObserver.register(); 

然而,我在控制台输出看起来是这样的:

console.log: myplugin: inside test 
console.log: myplugin: inside main 
console.log: myplugin: registering 
console.log: myplugin: registered 

然后它只是停止做任何事情,甚至当即时通讯随机浏览网页(应该产生一些体面的头数,因此应该触发我的'观察员'功能)。

我错过了什么?即时通讯仍然是新的Java脚本,并不是真的喜欢它.. 我已阅读了一些Mozilla指南和其他职位关于此,但他们似乎没有像我一样的问题。

总结:我的observer()函数永远不会运行,为什么?

回答

0

好吧,我找到了答案,我真的不知道为什么会这样,但好了,就到这里吧:

的“观察员”功能,其所谓的在我的代码需要如何被称为“观察” 。

真的很烦人。