最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Why PhantomJS render page use window.setTimeout - Stack Overflow

programmeradmin4浏览0评论

I am currently using PhantomJS for some doc's reports and looking in some examples i found this.

window.setTimeout(function () {
    page.render(output);
    console.log(output);
    phantom.exit();
}, 200);

I wonder why using window.setTimeout?? It affect web rendering??

Thanks... Nick.

I am currently using PhantomJS for some doc's reports and looking in some examples i found this.

window.setTimeout(function () {
    page.render(output);
    console.log(output);
    phantom.exit();
}, 200);

I wonder why using window.setTimeout?? It affect web rendering??

Thanks... Nick.

Share Improve this question asked Feb 25, 2014 at 22:56 NBPalominoNBPalomino 4811 gold badge7 silver badges15 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

The page.open callback is invoked only when the page is loaded. This does not means that everything has been loaded in your page and the js has been fully executed.

In addition, the js on the web page may not be executed immediately, especially if the site uses MVC client frameworks like AngularJS or Ember.js : a lot of stuff is done after the page load event.

Using setTimeout give you a little delay to be sure that your page is fully rendered.

Sometimes 200ms is not enought and you have to increase the duration.

Another way is to use the waitfor.js example : waits until a test condition is true such as an element is visisble.

发布评论

评论列表(0)

  1. 暂无评论