我使用PhantomJS 2.1.1拍摄手机屏幕截图,但其中一些屏幕并未正确显示,因为页面未完全呈现。我试图使用onLoadFinished事件,但它不起作用。PhantomJS onLoadFinished无法正常工作
这里是我的代码:
var system = require('system');
var args = system.args;
var page = require('webpage').create();
page.open(args[1]);
page.onLoadFinished = function (status) {
page.viewportSize = { width: 414, height: 736 };
page.clipRect = { top: 0, left: 0, width: 414, height: 736 };
page.render(args[2]);
console.log(args[2]);
phantom.exit();
});
它只是挂起并没有返回。我通过使用2秒硬编码延迟来解决这个问题,但这并不好,因为我不知道每个站点都会在2秒内加载。
这是硬编码延迟即时通讯使用:
page.open(args[1], function() {
page.viewportSize = { width: 414, height: 736 };
page.clipRect = { top: 0, left: 0, width: 414, height: 736 };
setTimeout(function() {
page.render(args[2]);
console.log(args[2]);
phantom.exit();
}, 2000);
});
如何获得的代码与适当的负载情况下工作?
有没有错误?使用[page.onError](http://phantomjs.org/api/webpage/handler/on-error.html)回调找出 – Vaviloff