Need help in checking the dom node position for different screen resoultions


We are working on an Open Source extension: Digital Assistant Client

I am recording the domnode by converting into json by domJson and saving into server. We can find the same recordednode by comparing the json attributes and matching to the original node on the page. We have one problem here when we search for the nodes sometimes we get similar nodes via json which has same property names. In that case we are trying to match the node position that we have recorded. When we try to match the node position in different screen resolutions, it gives us the wrong node. How do we solve this. My code is as given below

// calculate distance between selected node and matching node getDistance: function (node1, node2) {

const x = node1.x - node2.x; const y = node1.y - node2.y; const dist = Math.abs(Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2))); return dist;


If you capture window.devicePixelRatio perhaps you can use that to normalize your values to 100% effective zoom. Unfortunately, there will of course be rounding issues.