by hkjgkjy · 10y ago · 0 comments
I recently worked on an automated thumbnail generator which used PhantomJS (headless Webkit browser) to load some 20000 pages and screenshot them. The problem was that these pages had javascript code that would start loading resources long after `onload` and friends had fired. So the way I implemented onload was to monitor all resources and if there was delay of few seconds after the last one had finished, I'd consider the page loaded. It turned out to be quite robust.
However sometimes the page still hasn't finished drawing and so I do a couple of requestAnimationFrame's after the DOMCotentLoaded to ensure that everything is drawn to the screen buffer.