Skip to content

Instantly share code, notes, and snippets.

@TahaBoulehmi
Last active October 18, 2019 17:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TahaBoulehmi/0d27bbdf3eea0ac2c5a4cf7618210d9b to your computer and use it in GitHub Desktop.
Save TahaBoulehmi/0d27bbdf3eea0ac2c5a4cf7618210d9b to your computer and use it in GitHub Desktop.
This is a fix for Nightmare JS to allow making screenshots when the website forces a JavaScript redirection
var n = Nightmare({
switches: { 'ignore-certificate-errors': true, 'force-device-scale-factor': options.scale ? options.scale.toString() : '1' },
show: typeof options.show === 'boolean' ? options.show : true,
width: options.width || 1280,
height: options.height || 720
});
n
.viewport(options.width || 1280, options.height || 720)
.goto(url)
.wait(options.waitAfterSelector || "html")
.wait(options.waitMilliseconds || 1000)
.screenshot(
path || undefined,
options.clip || undefined
)
.then(function (buff) {
callback(null, buff);
})
.catch(function (err) {
return n
.screenshot(path || undefined, options.clip || undefined)
.then(function (buff) {
callback(null, buff);
})
.catch(function(){ callback(err) });
})
.finally(function() {
return n.end();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment