Firefox Addon: Sending data from main.js to dev tool tab

爷,独闯天下 提交于 2019-12-12 05:00:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!