3 ms·
Just out of curiosity - when does Chrome consider a page "loaded"? Is it the classic window.onload or something fancier?
by hkjgkjy 10y ago
Just out of curiosity - when does Chrome consider a page "loaded"? Is it the classic window.onload or something fancier?
- oxplot 10y agoNot 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.
- onion2k 10y agoThere 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.
- jayflux 10y agoAre 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/DOMContentLoaded https://developer.mozilla.org/en-US/docs/Web/Events/DOMConte...
- samwillis 10y agoTo 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.