Here is a Mozilla Javascript Module which allow to catch absolutely all requests based on their Content-Type Http header (ie Mime type) or their filename.
contentTypeObserver.js
(under LGPL License)
Components.classes["@mozilla.org/uriloader;1"].getService(Components.interfaces.nsIURILoader).registerContentListener( ...nsIURIContentListener... );But for some reason, this listener is bypassed here when the HTTP request contains a Content-Disposition header :(
So I give you there all Mozilla black magic needed to catch really all requests.
Hello world
Components.utils.import("resource://your-extension/contentTypeObserver.js"); var contentTypeObserver = {};// Tell if we must catch requests with this content-type // requestInfo is an object with 3 attributes : contentType, contentLength and fileName. contentTypeObserver.getRequestListener = function (requestInfo) { // Return a new instance of nsIWebProgressListener // (a new instance to avoid conflicts with multiple simultaneous downloads) return { onStartRequest : function (request, context) {
}, onStopRequest : function (request, context, statusCode) { }, onDataAvailable : function (request, context, inputStream, offset, count) { }
}; // There is an helper function that allow to automatically save this request to a file, // you just have to pass destinationFile argument which hold a nsIFile instance : return createSaveToFileRequestListener(requestInfo, destinationFile, function () { dump("file : "+destinationFile.spec+" downloaded! "); } }
addContentTypeObserver(contentTypeObserver);
Comments
You can use your Fediverse (i.e. Mastodon, among many others) account to reply to this post
(Note that comments from locked accounts won't be visible on the blog, but only to me)