Last active
October 18, 2019 17:42
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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