Add inline download management to your Nightmare scripts.
If you need to manage multiple downloads at the same time or want downloads to be processed in the background, check out the Nightmare download manager.
Require the library: and pass the Nightmare library as a reference to attach the plugin actions:
var Nightmare = require('nightmare');
require('nightmare-inline-download')(Nightmare);
... and that's it. You should now be able to handle downloads.
Allows for downloads to be saved to a custom location or cancelled. The possible values for action
are 'cancel'
, 'continue'
for default behavior, or a file path (file name and extension inclusive) to save the download to an alternative location. If yielded upon, .download()
returns a hash of download information:
Content-length
is set as a header.state
can be 'cancelled'
, 'interrupted'
, or 'completed'
.Defines whether or not all downloads should be ignored.
Sets the maximum time for the client to anticipate a .download()
call. If the call is not made, the download is automatically cancelled.
Sets the Electron path for where downloads are saved.
var Nightmare = require('nightmare');
require('nightmare-inline-download')(Nightmare);
var nightmare = Nightmare();
var downloadInfo = nightmare
.goto('https://github.com/segmentio/nightmare')
.click('a[href="https://github.com/rosshinkley/nightmare-inline-download/blob/master/segmentio/nightmare/archive/master.zip"]')
.download('/some/other/path/master.zip');
// ... do something with downloadInfo, in an evaluate for example ...
.end()
.then(()=>console.log('done'));