Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

phantomjs not waiting for "full" page load

I'm using PhantomJS v1.4.1 to load some web pages. I don't have access to their server-side, I just getting links pointing to them. I'm using obsolete version of Phantom because I need to support Adobe Flash on that web pages.

The problem is many web-sites are loading their minor content async and that's why Phantom's onLoadFinished callback (analogue for onLoad in HTML) fired too early when not everything still has loaded. Can anyone suggest how can I wait for full load of a webpage to make, for example, a screenshot with all dynamic content like ads?

like image 314
nilfalse Avatar asked Jul 05 '12 07:07

nilfalse


1 Answers

Another approach is to just ask PhantomJS to wait for a bit after the page has loaded before doing the render, as per the regular rasterize.js example, but with a longer timeout to allow the JavaScript to finish loading additional resources:

page.open(address, function (status) {     if (status !== 'success') {         console.log('Unable to load the address!');         phantom.exit();     } else {         window.setTimeout(function () {             page.render(output);             phantom.exit();         }, 1000); // Change timeout as required to allow sufficient time      } }); 
like image 181
rhunwicks Avatar answered Sep 18 '22 19:09

rhunwicks