I am trying to get the NaturalWidth and NaturalHeight of an image without loading it, in order to speed things up. Is there a way to do that? Thank you !
EDIT: I was told to share some code but I don't really know what to share.
Here is what I use to get all the sizes of images:
const images_datas = await this.page.$$eval('img', imgs => {
var images_data = []
var empty_images = 0
imgs.forEach(img => {
if(img.naturalWidth*img.naturalHeight == 0 || ( img.naturalHeight == 1 && img.naturalWidth == 1)){
empty_images++
} else {
images_data.push({'url': img.src, 'width': img.naturalWidth, 'height' : img.naturalHeight, 'alt' : img.alt})
}
});
return {'images_data': images_data, 'nb_empty_images': empty_images}
} );
And the code I use to prevent the images from loading.
await page.setRequestInterception(true);
page.on('request', request => {
if (request.resourceType() === 'image')
request.abort();
else
request.continue();
});
But the two codes do not work together...