headless: Implement screenshot capturing
(based on patch from skyostil@, also sets default window
size to 800x600 to enable basic snapshot support)
With the --screenshot option, headless shell will save a
PNG screenshot of the loaded page.
Not an answer to your question, but somewhat related:
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.
To add to what oxplot and onion2k said, with both PhantomJS and Electron (when using xvfb) I have found that waiting for the DOMCotentLoaded or with PhantomJS the onLoadFinished event (I think this is similar to documentRequestIdleCallback) usually works.
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.
There are a few events that get fired during a page load. DOMCotentLoaded is fired when the page and all its assets are loaded, so that's usually considered the point at which it's finished loading. With modern JS based pages that sometimes isn't enough though, so new browsers have documentRequestIdleCallback which fires a callback when the browser isn't busy, which is quite useful.
Are you not confusing DOMContentLoaded with window.load?
DCL doesn't wait for assets last time I checked, it only waits until the page is parsed and a tree has been created.
.load waits for assets
https://developer.mozilla.org/en-US/docs/Web/Events/DOMConte...