I am using the Firefox Addon SDK to create something that monitors and displays HTTP traffic in a browser. Like HTTPFox or Live HTTP Headers . I'm interested in determining which tab in the browser (if any) generated the request
Using observer-service I am tracking the events of "http-on-study-response". I have code similar to the following to determine the nsIDomWindow that generated the request:
const observer = require("observer-service"),
{Ci} = require("chrome");
function getTabFromChannel(channel) {
try {
var noteCB= channel.notificationCallbacks ? channel.notificationCallbacks : channel.loadGroup.notificationCallbacks;
if (!noteCB) { return null; }
var domWin = noteCB.getInterface(Ci.nsIDOMWindow);
return domWin.top;
} catch (e) {
dump(e + "\n");
return null;
}
}
function logHTTPTraffic(sub, data) {
sub.QueryInterface(Ci.nsIHttpChannel);
var ab = getTabFromChannel(sub);
console.log(tab);
}
observer.add("http-on-examine-response", logHTTPTraffic);
Mostly cut out from the documentation on how to identify the browser that generated the request . Some of them are also taken from the Google PageSpeed of Firefox.
nsIDOMWindow domWin SDK:
- , URL-, URL- domWin, , URL-.