Firefox Addon Downloads.jsm -


i'm trying use downloads.jsm lib of firefox (it's new in firefox 23) in jetpack addin.

var {cu} = require("chrome"); //works fine const {downloads} = cu.import("resource://gre/modules/downloads.jsm"); //works fine 

but executing either of these functions has no effect:

download = downloads.createdownload({source: "http://cdn.sstatic.net", target: "/tmp/kaki.html"}); //download object has no function "start" downloads.simpledownload("http://cdn.sstatic.net","/tmp/kaki.html"); 

documentation: https://developer.mozilla.org/en-us/docs/mozilla/javascript_code_modules/downloads.jsm https://developer.mozilla.org/en-us/docs/mozilla/javascript_code_modules/downloads.jsm/download

do have idea, how use these functions? haven't found examples on web

the api functions return promise, not actual download object.

in short, following should work:

const {downloads} = cu.import("resource://gre/modules/downloads.jsm", {}); var downloadpromise = downloads.createdownload({source: "http://cdn.sstatic.net", target: "/tmp/kaki.html"}) downloadpromise.then(function success(d) {   d.start(); }); 

read on promises, , make dealing them lot more fun, task.jsm

the api did change quite bit recently; documented current aurora-25 or later api. "old" api documented within source.

a more complete example firefox <25 support available in gist.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -