繁体   English   中英

Firefox插件:从XMLHttpRequest获取选项卡

[英]Firefox addon: Getting tab from XMLHttpRequest

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

知道我怎么能得到浏览器?

谢谢

试试这个代码( 来自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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM