1

Did the latest version of android chrome break jquery pageY values or am I missing something completely? Specifically the pageX/pageY values returned from a mouse event.

<script>
$( document ).on( "click", function( event ) {
  $( "#log" ).text( "pageX: " + event.pageX + ", pageY: " + event.pageY );
});
</script>

http://api.jquery.com/event.pagex/

Everything looks great on Windows Chrome, or Android Firefox. The values displayed on this page when tapping/hovering are WAY wrong for android chrome. Negative numbers, larger number than expected, numbers changing when zooming/scrolling when they shouldn't etc. I've tried a couple different builds of jquery on the jsfiddle site, all broken for android chrome.

Here's a fiddle with it changed to "click" instead of "mousemove":

http://jsfiddle.net/eLvbmqdg/4/

Again, desktop, iphone, and android firefox work as expected. Android chrome 38.0.2125.102 seems very broken.

I have code in production that expects pageY to be... accurate. That code hasn't been changed in a while, and all of a sudden things are breaking.

Ideas? Is anyone else seeing this? Was this always broken somehow?

enter image description here

Will Shaver
  • 12,471
  • 5
  • 49
  • 64

2 Answers2

1

I'm also seeing this on Chrome for Android version 38.0.2125.102 on a Nexus 5. I'm not sure when this bug was introduced, but it is now breaking code we depend on when looking up event.pageY values.

I inspected my device and it's clear that the event.pageY values reported are wrong when compared to the desktop. Also downgrading to an earlier version of Chrome (32.0.1700.99) for Android reports the correct event.pageY value.

rosh93
  • 11
  • 1
0

So this is a bad hack. I hate putting version strings in browser workarounds. I tried doing one based on the window offset or size of the item you're clicking on, but with large enough images it won't work 100% of the time. Hopefully this will get fixed quickly, but if you're coming here looking for an answer to this specific bug in Android Chrome, here's what I did to fix it.

Future versions of android chrome may have this same bug, and we might need to have a running list of versions that are broken. If you come to this page with a different broken version, please put it in the comments below. (Also please upvote the chromium issue.)

var clientY = evt.clientY;
var clientX = evt.clientX;
var pageX = evt.pageX;
var pageY = evt.pageY;

if(window.navigator.appVersion.match(/Chrome\/(.*?) /)[1] == "38.0.2125.102"){
 //hack to fix the chromium bug
 //https://code.google.com/p/chromium/issues/detail?id=423802
 clientX -= window.scrollX;
 clientY -= window.scrollY;
 pageX -= window.scrollX;
 pageY -= window.scrollY;
}
Will Shaver
  • 12,471
  • 5
  • 49
  • 64