That would be very difficult to do. It will be difficult for you to do it reliably in such a way that it works on any website, even on websites that you do not control.
What you can do is to walk around the entire DOM and figure out the rectangle that each visible element occupies, but how do you determine the visibility? Sometimes what you see as a space is a div with a white background that sits on top of some other div, sometimes you see an element with a fixed body, sometimes it is slightly off-white or a different color, etc.
thomasrutter
source share