Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NightmareJS screenshot callback

I'm using this framework to make screenshots of several urls. The process of taking the screenshot is async, and the method does not provide a way to execute a callback, and I want to execute a callback when each screenshot is made on this script:

nightmare = new Nightmare();
urls.forEach(function (url) {
    nightmare.goto(url).screenshot(path);
});

nightmare.run(function () {
  console.log('finished all');
});

Any ideas how can I do this?

like image 475
fernandopasik Avatar asked Feb 06 '26 01:02

fernandopasik


1 Answers

I found a way to do this, with the "use" method for executing plugins.

nightmare = new Nightmare();
urls.forEach(function (url) {
    nightmare.goto(url).screenshot(path).use(function () {
        console.log('finished one');
    });
});

nightmare.run(function () {
    console.log('finished all');
});
like image 189
fernandopasik Avatar answered Feb 07 '26 21:02

fernandopasik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!