1
我想用惡夢獲取我的web應用程序的屏幕截圖。如果在運行代碼時沒有錯誤,並且退出是乾淨的,則不會留下任何phantomjs實例。如何用夢魘正確地停止phantomjs實例
var Nightmare = require('nightmare');
var Screenshot = require('nightmare-screenshot');
var nightmare = new Nightmare();
var url = process.argv[2];
var url = process.argv[3];
nightmare
.goto(url)
.wait('#selector')
.use(Screenshot.screenshotSelector(path, '#selector'))
.run(function (err, nightmare) {
if (err)
console.log('Error');
else
console.log('Done.');
nightmare.teardownInstance();
nightmare.end();
});
但是,當有一些錯誤,如網絡沒有運行時,選擇器不存在。幻影的實例仍然未被使用。
$ ps -ax | grep phantom
6065 ttys004 0:00.00 grep phantom
6050 ttys005 0:02.87 phantomjs --load-images=true --ignore-ssl-errors=true --ssl-protocol=any --web-security=true /.../node_modules/phantom/shim.js 13201 127.0.0.1
即使有任何錯誤我怎麼能正確地退出它的實例?
是的,我也認爲這可能是問題。順便說一句,你是如何發現它每隔250ms檢查一次的? – surenyonjan
你可以在nightmarejs代碼中找到它。 –