简体   繁体   English

如何从firefox扩展xpcom组件内部获取启动GET请求的页面元素?

[英]How to get the page element initiating a GET request from inside a firefox extension xpcom component?

I have a firefox extension xpcom component that listens to http-on-modify-request and gets the location of the page making the request: 我有一个firefox扩展xpcom组件,它侦听http-on-modify-request并获取发出请求的页面的位置:

getLocationOfOriginatingWindow: function (httpChannel) {
    try {  
        var notificationCallbacks;

        if (httpChannel.notificationCallbacks) {
            notificationCallbacks = httpChannel.notificationCallbacks;
        }
        else if (httpChannel.loadGroup && httpChannel.loadGroup.notificationCallbacks) {
            notificationCallbacks = httpChannel.loadGroup.notificationCallbacks;        
        }
        else {
            return null;
        }

        return notificationCallbacks.getInterface(Components.interfaces.nsIDOMWindow).top.location;  
    }  
    catch (e) {
        DEBUG("Exception getting Window Location: " + e + "\nChannel URI: " + httpChannel.URI.spec); 
        return null;  
    }  
},

I would also like to get the page element that made the request (img, script etc.). 我还想获得发出请求的页面元素(img,脚本等)。 Is there a way to do the from the httpChannel? 有没有一种方法可以从httpChannel中进行?

There's no specific way to tell what made the request from the HTTP observer, since there are so many different ways of triggering requests, such as a CSS background image rollover. 由于有许多不同的触发请求的方式,例如CSS背景图像翻转,因此没有特定的方法来告诉HTTP观察者发出了什么请求。 You could try attacking the problem from the content policy end, which I believe gives you more information. 您可以尝试从内容策略一端来解决问题,我相信它可以为您提供更多信息。

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

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