Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am currently building an extension which is required to capture only HTTP request being made by the TOP frame browser (Not capture every HTTP request being initiated) before they are being sent out and the response received. Is that possible to handle in a Firefox extension?

I currently managed to capture all HTTP requests being made via the following code snippet:

JavaScript
var httpRequestObserver =
{
    observe: function(aSubject, aTopic, aData)
    {
	var browser = this.getBrowserFromChannel(subject);
        if (topic == "http-on-modify-request") {
            var httpChannel = subject.QueryInterface(Ci.nsIHttpChannel);
        }
		
    },
	
    get observerService() {
        return Cc["@mozilla.org/observer-service;1"]
                         .getService(Ci.nsIObserverService);
    },

    register: function()
    {
        this.observerService.addObserver(this, "http-on-opening-request", false);
    },

    unregister: function()
    {
        this.observerService.removeObserver(this, "http-on-opening-request");
    }
};

httpRequestObserver.register();
var {Cc, Ci} = require("chrome");


My question is, how can I update my code snippet to have it capture only HTTP requests being made by the top level browser (In other words, navigation requests made by a tab within the browser).

Thanks a bunch in advance!
Posted
Comments
Sergey Alexandrovich Kryukov 26-Jun-14 12:55pm    
What is that, "top level browser", exactly? :-)
The explanation about tabs are not clear; tabs don't send HTTP requests. Perhaps you mean only the requests from the address line (and View/Reload)...
Why, by the way?
—SA
Daroosh 27-Jun-14 5:14am    
Hi Sergey, Yes thats exactly what I mean, the request from the address bar. Thanks!
Sergey Alexandrovich Kryukov 27-Jun-14 11:40am    
Sorry that I don't know the solution (it should be Mozilla-specific), but thank you for the clarification.
Well, one apparent solution would be capturing all requests but filtering out only those without a referrer (which is prescribed in an HTTP request), but this is probably not good enough.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900