I am working on an application that compares the displayed DOM in different browsers to find the differences. I see this as an alternative to the screenshot. In addition, this can be done programmatically with much less false positives (at least what I thought).
I calculate the actual position of the elements through element.getBoundingClientRect (), as suggested here: get the xy position of the html element .
I tried this on Firefox and Chrome and created a JSON DOM structure. Now I am really confused by what I have. I know that browsers handle pixel values differently at the sub-pixel level, but that’s not how Chrome always has rounded numbers, and Firefox always has fractions. It almost always looks like this:
Firefox
{ "name": "SPAN", "style": { "display": "block", "top": "1390.5", "left": "824.61669921875", "width": "123.38333129882812", "height": "27" } }
Chrome
{ "name": "SPAN", "style": { "display": "block", "top": "1390", "left": "824.640625", "width": "123.359375", "height": "27" } }
The top value in chrome is always an integer, whereas in firefox it is always the same value, but either .5 or .25 above.
The height is either exactly 1 or .5 higher than chrome.
All other values are sometimes fractions in both browsers. If they are fractions, they are never equal (firefox always has a higher value). If they are whole, they are the same.
I would never have expected something like that. It is especially strange that the values are top and height . I would understand that the rendering is just different, and this leads to (irregular !!) different pixel values.
So my question is: if I do this comparison, can I get any rules from it? Does anyone know firefox rounding rules? Or should I make a tolerant comparison, where I check if the values differ from unity by unity?
Update:
If you quickly want to test this yourself, just go to http://example.com/ (since it has a pretty small DOM) and enter document.getElementsByTagName("body")[0].getBoundingClientRect() in the javascript console on firefox and chrome. Y, height and upper values are insanely long float values in firefox, while they are shorter and strangely rounded in chrome.