background preloader

Add-on

Facebook Twitter

Firefox addon - How to get mime type of the file before downloading it. Detect file download in Firefox Extension. Intercepting Page Loads - XUL. There are several ways to detect and intercept loading of web pages and their content, be it only to realize when it happens, modify their contents, or to block them and do something else instead.

Intercepting Page Loads - XUL

Some of the techniques presented here apply only to content loaded in the main browser area, while others detect content being loaded in other XUL windows, or even detect XUL content being loaded. Also, the different techniques tap into different steps of the load process. Which one you should use solely depends on your needs. We will start with the simplest one, which is also the most common to use. Note: Performance is very important when it comes to add-ons and page loads. Downloading Files - Code snippets. Downloading files Components.utils.import(" const WebBrowserPersist = Components.Constructor("@mozilla.org/embedding/browser/nsWebBrowserPersist;1", "nsIWebBrowserPersist"); var persist = WebBrowserPersist(); var targetFile = Services.dirsvc.get("Desk", Ci.nsIFile); targetFile.append("file.bin");var privacy = PrivateBrowsingUtils.privacyContextFromWindow(urlSourceWindow); persist.persistFlags = persist.PERSIST_FLAGS_FROM_CACHE | persist.PERSIST_FLAGS_REPLACE_EXISTING_FILES; persist.saveURI(uriToSave, null, null, null, "", targetFile, privacy); If you don't need detailed progress information, you might be happier with nsIDownloader.

Downloading Files - Code snippets

Downloading files with a Firefox addon.