Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Can I Tell If a Background-Image Loaded Successfully ... AFTER The Fact?

There are several Stack Overflow questions like How can I check if a background image is loaded? which are similar to mine. They attempt to run code when an element's background-image loads, and accomplish this by adding an onload handler to the element.

But what if you are running (for instance) a Puppeteer script, which checks the page after it has already loaded? In that case you can't add onload handlers.

Is there any way to verify that the background-image of an element loaded, "after the fact", without using onload?

The only way I can think of is to grab their background-image style, then fetch the image myself to see if it loads ... but that seems a lot slower than just asking the browser (somehow) if the image loaded ... especially if I'm checking a lot of background-images.

like image 544
machineghost Avatar asked Feb 02 '26 19:02

machineghost


1 Answers

Puppeteer has a config for pages to check the number of idle connections. So the images should be loaded while there are no more requests than specified in 500ms.

await page.goto('https://www.google.com/', {"waitUntil" : "networkidle0"});
like image 135
Filas Siuma Avatar answered Feb 05 '26 08:02

Filas Siuma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!