Define a tab by making a request in the Firefox Addon SDK

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-.

+5
4

. , , getTabForWindow() api-utils/lib/tabs/tab.js , . :

var tabsLib = require("sdk/tabs/tab.js");
return tabsLib.getTabForWindow(domWin.top);
+3

API , /... ( 1.15) :

return require("sdk/tabs/utils").getTabForWindow(domWin.top);
+3

Addon SDK 1.13:

var tabsLib = require("tabs/tab.js");

var tabsLib = require("sdk/tabs/helpers.js");

0

- :

SDK API WebExtensions, ,

var a_tab = require ( "sdk/tabs/utils" ). getTabForContentWindow ()

"", , ,

worker.tab PageMod.

, a_tab id, linkedPanel, id.

0

All Articles