本文介绍了NightmareJS屏幕截图回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用此框架制作几个URL的屏幕截图.截屏的过程是异步的,并且该方法没有提供执行回调的方法,并且我想在此脚本上制作每个截屏时执行回调:
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?
推荐答案
我找到了一种使用"use"方法执行插件的方法.
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');
});
这篇关于NightmareJS屏幕截图回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!