Getting mouse coordinates is very simple, put this in the content script :
document.onmousemove = function(e) { var x = e.pageX; var y = e.pageY;
Essentially, we assign a function to the onmousemove event of the entire page and get the mouse coordinates from the event object ( e ).
However, I'm not quite sure what you mean by this:
then use these coordinates to check if the person clicked in that position?
Do you want to check if the user clicks something like a button? In this case, you can simply subscribe to this button (or any other element) as follows:
document.getElementById("some_element").onclick = function(e) { alert("User clicked button!"); };
To record all mouse clicks and where they are:
document.onclick = function(e) {
Note that mouse coordinates are still available in the event object ( e ).
If you need coordinates when the user clicks an arbitrary location, this does the trick:
document.onclick = function(e) { var x = e.pageX; var y = e.pageY; alert("User clicked at position (" + x + "," + y + ")") };
source share