Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

DownloadLastDir.jsm

This article needs a technical review. How you can help.

The DownloadLastDir.jsm JavaScript code module lets you retrieve the path of the last directory into which a download occurred.

To use this, you first need to import the code module into your JavaScript scope:

Components.utils.import("resource://gre/modules/DownloadLastDir.jsm");

If you are using Addon SDK, you can import the code module as:

let { Cu } = require("chrome");
let DownloadLastDir = Cu.import("resource://gre/modules/DownloadLastDir.jsm").DownloadLastDir;

Once you've imported the module, you can then use the DownloadLastDir object it exports.

Using the DownloadLastDir object

To determine or set the path into which the last download occurred:

// file is an nsIFile
var file = DownloadLastDir.file;
DownloadLastDir.file = file;

You can also set and retrieve this information on a site-by-site basis.

To set the path, use setFile:

// file is an nsIFile
DownloadLastDir.setFile(uri, file);

To retrieve the path in Firefox 26 or later, use getFileAsync:

DownloadLastDir.getFileAsync(uri, function (file) {
  // file is an nsIFile
  console.log(file);
});

Deprecated since Gecko 26.0 To retrieve the path in Firefox 25 or earlier, use getFile:

// file is an nsIFile
var file = gDownloadLastDir.getFile(uri);
console.log(file);

Private browsing mode

When browsing normally, the browser uses the browser.download.lastDir preference to store the last download directory path. However, when private browsing mode is enabled, the last download directory path is instead maintained in memory, and the preference is not changed.

When the user exits private browsing mode, the last download directory value is reverted to the preference's value.

When history is cleared

When the user's browsing history is cleared, the value of the last download directory path is restored to the platform's default download directory path.

See also

Document Tags and Contributors

 Contributors to this page: rahul1210, adw, teoli, darktrojan, Sheppy
 Last updated by: rahul1210,