Пытаюсь перейти на новый ESR, но...
на 10esr работал скрипт:

скрытый текст

Выделить код

Код:

try { var out = "";
var SourceUrl = unescape("SourceUrl");
var HeaderUrl = unescape("HeaderUrl");

var destinationfullpath = "Path"+fileName;

var dm = Components.classes["@mozilla.org/download-manager;1"].getService(Components.interfaces.nsIDownloadManager);

var ioService  = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
var uri = ioService.newURI(SourceUrl, null , null);
var referrerUri = ioService.newURI(HeaderUrl, null, null);
var url = uri.QueryInterface(Components.interfaces.nsIURL);

var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
file.initWithPath(destinationfullpath);
if( !file.exists() || !file.isFile() ) { file.create(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0644) };
var fileURI = ioService.newFileURI(file);

var nsIWBP = Components.interfaces.nsIWebBrowserPersist;
var persist = Components.classes["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"].createInstance(Components.interfaces.nsIWebBrowserPersist);
var flags = nsIWBP.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION | nsIWBP.PERSIST_FLAGS_REPLACE_EXISTING_FILES | nsIWBP.PERSIST_FLAGS_BYPASS_CACHE;

persist.persistFlags = flags;

var download = dm.addDownload ( dm.DOWNLOAD_TYPE_DOWNLOAD, uri, fileURI, fileName, null, null, null, null, persist);
persist.progressListener = download;
persist.saveURI(uri, null, referrerUri, null, "", download.targetFile, null);
 }catch(e){out = e.name}finally{out;}


потом выручал:
скрытый текст

Выделить код

Код:

try { var out = "";
var SourceUrl = unescape("SourceUrl");

var destinationfullpath = path+fileName;

var tr = Components.classes["@mozilla.org/transfer;1"].createInstance(Components.interfaces.nsITransfer);

var ioService  = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
var uri = ioService.newURI(SourceUrl, null , null);
var url = uri.QueryInterface(Components.interfaces.nsIURL);

var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
file.initWithPath(destinationfullpath);
var fileURI = ioService.newFileURI(file);

var nsIWBP = Components.interfaces.nsIWebBrowserPersist;
var persist = Components.classes["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"].createInstance(Components.interfaces.nsIWebBrowserPersist);
var flags = nsIWBP.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION | nsIWBP.PERSIST_FLAGS_REPLACE_EXISTING_FILES | nsIWBP.PERSIST_FLAGS_BYPASS_CACHE;

persist.persistFlags = flags;

tr.init(uri , fileURI , fileName, null , null , null , null );
persist.progressListener = tr;
persist.saveURI(uri, null, null, null, "", fileURI);
 }catch(e){out = e.name}finally{out;}


сейчас пытаюсь сделать скрипт под 45esr, но не удаётся найти подходящий пример. Вот такой вариант не работает:

Выделить код

Код:

try { var out = "";
var sDownloadUrl = unescape("sDownloadUrl");
var sFileName = "sFileName";
var sPath = "sFileName";

    Cu.import("resource://gre/modules/Downloads.jsm");
    Cu.import("resource://gre/modules/osfile.jsm")'
    Cu.import("resource://gre/modules/Task.jsm");

    Task.spawn(function () {'
        let list = yield Downloads.getList(Downloads.ALL);
        try {'
            let download = yield Downloads.createDownload({'
            source: sDownloadUrl,'
            target: OS.Path.join(sPath,sFileName)'
        });
        console.log('OS.Constants.Path.tmpDir='+OS.Constants.Path.tmpDir);
        list.add(download);
        download.start();
    }).then(null, Cu.reportError);
 }catch(e){out = e.name}finally{out;}

По идее скрипт должен добавлять URL в менеджер и запускать загрузку...