问题
I am trying to implement an addon that will intercept the HTTP response and then log it on to dev tool tab similar to the way XHRs are logged into web console.
Addon code has following files:
data/index.html
lib/main.js
I have defined devtoolTabDefinition :
devtoolTabDefinition = {
id: "logger",
ordinal: 3,
icon: "chrome://browser/skin/devtools/inspector-icon.png",
url: self.data.url("index.html"),
label: "HRRL",
tooltip: "HTTP Request Response Logger",
// Rest of the code
I have registered an observer,HttpResponseListener from Ci.nsIObserverService to observe "http-on-examine-response". HttpResponseListener intercepts the responses and I get the response string in it's onDataAvailable method.
I need to send rather add this response string to the dev tool tab's index.html.
AFAIK I don't have to use content script because I have nothing to do with the main page window. I just need to intercept the response and log it in dev tool tab.
Thanks in advance.
回答1:
If you look at the example, the communications channel is set up in the build method, which you don't show in your code. You can see a working example of this approach here:
https://github.com/canuckistani/jetpack-devtools-template/blob/master/lib/main.js#L42-L51
*Aside: starting with Firefox 34 (now in nightly) there will be new devtools apis to make this all easier, for a really simple example see here.
来源:https://stackoverflow.com/questions/25114970/firefox-addon-sending-data-from-main-js-to-dev-tool-tab