Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to see which srcset image a browser is using with browser developer tools

I've been trying to see which srcset image my browser is using via the browsers developer tools, but apart from using the network tab to see which image it fetches i can't tell.

Using the network tab would usually be fine, but sometimes I've noticed that it will fetch 2 image versions at different sizes, this would happen if one break point is at 600 and another at 900 and the browser was currently at 750px wide.

(Ive tried this both on Chrome & FireFox, and it seems chrome will pull down both images in certain cases, but FireFox seems to only ever pull down one)

The reason I want to know is I'm interested if it pulls down two image srcset dose it swap between them automatically as i scale the browser window ? This is can't tell as by inspecting the element it just gives the raw html of the img element, not the actual img srcset option its using.

like image 338
sam Avatar asked Jun 17 '15 19:06

sam


People also ask

How does browser choose Srcset?

The sizes attribute determines the media condition that applies to the current device width (the first media condition that applies is selected). Then, the browser checks the srcset attribute to find the image that most closely matches the slot size determined by the sizes attribute.

What is Srcset in image?

srcset defines the set of images we will allow the browser to choose between, and what size each image is. Each set of image information is separated from the previous one by a comma.

Do you need SRC with Srcset?

Yes it's valid. The src is used as a fallback if the browser doesn't support srcset. However if you are using it just for retina stuff you don't really need to use picturefill. I tend to just let it degrade back to the normal src if the browser doesn't support srcset.


2 Answers

The image has a property currentSrc, you can log it or inspect it with several tools:

  • In chrome developer tools inspect the element, then click the properties tab.
  • In Firefox developer tools inspect the element, right click and select DOM from the context menu.

You will see an entry for currentSrc: with the actual image source.

enter image description here

like image 134
simsom Avatar answered Sep 24 '22 20:09

simsom


I had problems with this today and I found that you can monitor the variable:

  1. Show the console drawer (You can do it pressing ESC too)

enter image description here

  1. Create live expression (I created 2, the currentSrc of the selected element and the innerWidth)

enter image description here

The live expression watches the current srcset of the img tag selected. It works with the img inside the picture tag too.

like image 20
Doc Kodam Avatar answered Sep 26 '22 20:09

Doc Kodam