gpt4 book ai didi

javascript - Firefox 插件 : Getting tab from XMLHttpRequest

转载 作者:搜寻专家 更新时间:2023-11-01 04:37:09 25 4
gpt4 key购买 nike

我正在尝试使用以下代码将 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) 失败:“组件没有请求的接口(interface)”

知道我还能如何获得浏览器吗?

谢谢

最佳答案

试试这个代码(from 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;
}
}
}

注意许可证是 MPL 1.1/GPL 2.0/LGPL 2.1

关于javascript - Firefox 插件 : Getting tab from XMLHttpRequest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21082764/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com