Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
136
rated 0 times [  138] [ 2]  / answers: 1 / hits: 6003  / 11 Years ago, tue, february 25, 2014, 12:00:00

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.


More From » phantomjs

 Answers
4

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.


[#47401] Tuesday, February 25, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mathewb

Total Points: 535
Total Questions: 95
Total Answers: 96

Location: British Indian Ocean Territory
Member since Fri, Oct 15, 2021
3 Years ago
;