确定在Firefox Addon SDK中提出请求的选项卡 [英] Identify tab that made request in Firefox Addon SDK
问题描述
我使用 Firefox Addon SDK 来构建监视器并在浏览器中显示HTTP流量。与 HTTPFox 或 Live HTTP Headers 。我感兴趣的是确定浏览器中的哪个标签(如果有的话)生成了请求
使用 observer-service 我正在监视http-on-examine-response 事件。我有类似于下面的代码来识别生成请求的nsIDomWindow:
$ $ $ $ $ $ $ $ $ $ $ const observer = require(observer - 服务),
{Ci} = require(chrome);
函数getTabFromChannel(频道){
尝试{
var noteCB = channel.notificationCallbacks? channel.notificationCallbacks:channel.loadGroup.notificationCallbacks;
if(!noteCB){return null; }
var domWin = noteCB.getInterface(Ci.nsIDOMWindow);
返回domWin.top;
} catch(e){
dump(e +\\\
);
返回null;
函数logHTTPTraffic(sub,data){
sub.QueryInterface(Ci.nsIHttpChannel);
var ab = getTabFromChannel(sub);
console.log(tab);
}
observer.add(http-on-examine-response,logHTTPTraffic);
大多是从有关如何识别生成请求的浏览器的文档。有些也取自 是否有建议或首选的方式从 nsIDOMWindow object 我曾经考虑过这样一个hacky,就像扫描一个带有与domWin的URL匹配的URL的选项卡列表,但是我不得不担心具有相同URL的多个选项卡。 您必须继续使用内部软件包。从我所知道的, I'm using the Firefox Addon SDK to build something that monitors and displays the HTTP traffic in the browser. Similar to HTTPFox or Live HTTP Headers. I am interested in identifying which tab in the browser (if any) generated the request Using the observer-service I am monitoring for "http-on-examine-response" events. I have code like the following to identify the nsIDomWindow that generated the request: Mostly cribbed from the documentation for how to identify the browser that generated the request. Some is also taken from the Google PageSpeed Firefox addon. Is there a recommended or preferred way to go from the nsIDOMWindow object I've considered something hacky like scanning the tabs list for one with a URL that matches the URL for domWin, but then I have to worry about multiple tabs having the same URL. You have to keep using the internal packages. From what I can tell,
这篇关于确定在Firefox Addon SDK中提出请求的选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
domWin
添加到 SDK选项卡模块? p>
getTabForWindow()
函数在 api-utils / lib / tabs / tab.js
package does正是你想要的。未经测试的代码:
var tabsLib = require(sdk / tabs / tab.js);
返回tabsLib.getTabForWindow(domWin.top);
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);
domWin
to a tab element in the SDK tabs module?getTabForWindow()
function in api-utils/lib/tabs/tab.js
package does exactly what you want. Untested code:var tabsLib = require("sdk/tabs/tab.js");
return tabsLib.getTabForWindow(domWin.top);