js download and write file as it downloads code example
Example 1: javascript download file
browser.downloads.download({url: "https://example.org/image.png"})
Example 2: javascript download file
$('a#someID').attr({target: '_blank',
href : 'http://localhost/directory/file.pdf'});