[英]Firefox addon: Getting tab from XMLHttpRequest
I am trying to associate an XMLHttpRequest with a tab on the browser using the following code: 我正在尝试使用以下代码将XMLHttpRequest与浏览器上的选项卡相关联:
function getBrowserFromChannel(aChannel) {
var notificationCallbacks =
aChannel.notificationCallbacks ?
aChannel.notificationCallbacks :
aChannel.loadGroup.notificationCallbacks;
if (!notificationCallbacks) {
console.log("no callbacks");
return (0);
}
var loadContext = notificationCallbacks.getInterface(Ci.nsILoadContext);
getInterface(Ci.nsILoadContext) fails with: "Component does not have requested interface" getInterface(Ci.nsILoadContext)失败,并显示:“组件没有请求的接口”
Any idea how else I can get the browser? 知道我怎么能得到浏览器?
Thanks 谢谢
Try this code ( from Lightbeam ): 试试这个代码( 来自Lightbeam ):
function getLoadContext(aRequest) {
try {
// first try the notification callbacks
var loadContext = aRequest.QueryInterface(Ci.nsIChannel)
.notificationCallbacks.getInterface(Ci.nsILoadContext);
return loadContext;
} catch (ex) {
// fail over to trying the load group
try {
if (!aRequest.loadGroup) return null;
var loadContext = aRequest.loadGroup.notificationCallbacks.getInterface(Ci.nsILoadContext);
return loadContext;
} catch (ex) {
return null;
}
}
}
Note the license is MPL 1.1/GPL 2.0/LGPL 2.1 注意许可证是MPL 1.1 / GPL 2.0 / LGPL 2.1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.