My firefox addon (addon-sdk) has a feature where it listens to http responses and blocks them if the content type matches certain specified types. However, I do not want to listen to image, JavaScript files, or XHR (ajax) responses. Is there a way to filter out or identify XHR requests specifically so that unnecessary resources are not wasted on processing these responses?
A similar functionality can be achieved in chrome extensions by using "details.type" which can be main_frame, image, xhr, etc.
var httpResponseObserver =
{
observe: function(subject, topic, data)
{
if (topic == "http-on-examine-response")
{
var channel = subject.QueryInterface(Ci.nsIHttpChannel);
var contentType;
try {
contentType = channel.getResponseHeader('Content-Type');
if (/\b(?:xml|rss|javascript|vnd|json|html|text|image|ocsp|x-shockwave-flash)\b/.test(contentType))
{
return;
}
}
catch(error) {
return;
}
}
}