Issue 141840 in chromium: document.elementFromPoint returns a wrong element

390 views
Skip to first unread message

chro...@googlecode.com

unread,
Aug 10, 2012, 8:34:27 AM8/10/12
to chromi...@chromium.org
Status: Unconfirmed
Owner: ----
Labels: OS-Android Pri-2

New issue 141840 by ivan.per...@openbravo.com: document.elementFromPoint
returns a wrong element
http://code.google.com/p/chromium/issues/detail?id=141840

Chrome Version: 18.0.1025123
URLs (if applicable): See attached file

Android version: 4.0.3
Build number: IML74K.BULPD
Device: Samsung Galaxy S II (GT-I9100)

Behavior in Chrome for Android Browser (if applicable):

Steps to reproduce:
1. Save the attached file in an mobile accessible location(webserver) and
load it with a device using Chrome for Android
2. Tap/Touch the 3rd button
3. You'll see the x,y coordinates and the detected button

Expected result:
* You should get the DOM element nearest to the x,y position, e.g. If I tap
the B3, the B3 should be the element returned
*
http://dev.w3.org/csswg/cssom-view/#widl-Document-elementFromPoint-Element-float-x-float-y
* https://developer.mozilla.org/en-US/docs/DOM/document.elementFromPoint

Actual result:
* You get a wrong button. When you tap the B3, you get the reference B2,
when you tap B2, you get a reference to B1

Extra notes:
* This example works fine in the following mobile browsers:
- Default Browser for Android (4.0.3)
- Safari on iOS 5 (5.1.1)
- Chromium 21.0.1180.75 simulating touch events with Developer Tools



Attachments:
element.html 1.2 KB

chro...@googlecode.com

unread,
Aug 10, 2012, 9:47:55 AM8/10/12
to chromi...@chromium.org

Comment #1 on issue 141840 by ben.combee: document.elementFromPoint returns
We've seen this behavior in testing Enyo on Chrome for Android, see
https://enyojs.atlassian.net/browse/ENYO-789

chro...@googlecode.com

unread,
Aug 10, 2012, 8:15:41 PM8/10/12
to chromi...@chromium.org

Comment #2 on issue 141840 by ben.combee: document.elementFromPoint returns
Tested in Chrome 18.0.1025.166 on Nexus 7 running Android 4.1.1 and
reproduced problem tapping third button.

Tested in Chrome 18.0.1025.166 on Sony Tablet S running Android 4.0.3 and
did not see reproduction.

I suspect this is related to device DPI and its relation to CSS pixels.

chro...@googlecode.com

unread,
Aug 11, 2012, 7:57:30 AM8/11/12
to chromi...@chromium.org

Comment #3 on issue 141840 by knunn...@gmail.com: document.elementFromPoint
The issue is that elementFromPoint is expecting the screenX and screenY
coordinates, which is wrong. The elementFromPoint implementation should
take into account the scaling of the webpage.

chro...@googlecode.com

unread,
Aug 29, 2012, 5:18:09 PM8/29/12
to chromi...@chromium.org

Comment #4 on issue 141840 by ben.combee: document.elementFromPoint returns
I'm working around by multiplying X & Y coordinates by
window.devicePixelRatio before calling elementFromPoint on Android Chrome
18 and earlier. Hope I don't need to apply this fix to next version.

chro...@googlecode.com

unread,
Oct 1, 2012, 6:52:37 PM10/1/12
to chromi...@chromium.org

Comment #5 on issue 141840 by gareth98...@gmail.com:
document.elementFromPoint returns a wrong element
http://code.google.com/p/chromium/issues/detail?id=141840

Just to say this also happens in the latest build on the Nexus 7 (Chrome
18.0.1025308).

Conversely it also works correctly on iOS6 and in both Opera Mobile
12.00.ADR-1207201819 and the Firefox 16.0 Beta for Android.

chro...@googlecode.com

unread,
Oct 18, 2012, 6:46:27 PM10/18/12
to chromi...@chromium.org
Updates:
Owner: astra...@chromium.org
Cc: srika...@chromium.org jeremy...@chromium.org dcbl...@chromium.org
Labels: -Pri-2 Pri-1

Comment #6 on issue 141840 by anant...@chromium.org:
document.elementFromPoint returns a wrong element
http://code.google.com/p/chromium/issues/detail?id=141840

+adding astrange and srikanth to help triage this issue.

Increasing the priority since this impacts almost all users that get the to
google search results page on Clank, as it is causing issues on the search
results page toolbelt. Please ping me directly if you have questions. I'd
appreciate your help resolving this issue.

chro...@googlecode.com

unread,
Oct 18, 2012, 7:47:26 PM10/18/12
to chromi...@chromium.org

Comment #11 on issue 141840 by knunn...@gmail.com:
document.elementFromPoint returns a wrong element
http://code.google.com/p/chromium/issues/detail?id=141840

It would probably be a bad idea to try and maintain compatibility with
hacks devised to fix a bug. Make the change visible to developers and they
will remove the hacks.

chro...@googlecode.com

unread,
Oct 18, 2012, 7:52:26 PM10/18/12
to chromi...@chromium.org

Comment #12 on issue 141840 by ben.combee: document.elementFromPoint
I'm fine with a fix as long as the Chrome version number is >18. I don't
know of a way to feature detect this problem, and since it also affects the
webview on Android 4.1 which isn't upgraded when Chrome is upgraded, we
have to live with the fix forever.

chro...@googlecode.com

unread,
Oct 18, 2012, 8:28:29 PM10/18/12
to chromi...@chromium.org

Comment #14 on issue 141840 by wangxian...@chromium.org:
document.elementFromPoint returns a wrong element
http://code.google.com/p/chromium/issues/detail?id=141840

Hopefully the next m24 release will include the fix.

chro...@googlecode.com

unread,
Oct 23, 2012, 6:21:02 PM10/23/12
to chromi...@chromium.org

Comment #17 on issue 141840 by ben.combee: document.elementFromPoint
Update: I found a problem with the divide by devicePixelRatio workaround,
and ended up figuring out that passing the screenX/Y from an event gives
the correct element, but clientX/Y does not. clientX/Y * dpr is screenX/Y
when the page is scrolled to 0,0, but if you scroll the page down, that
relation doesn't hold.

chro...@googlecode.com

unread,
Oct 25, 2012, 8:46:48 PM10/25/12
to chromi...@chromium.org
Updates:
Owner: trc...@chromium.org
Cc: wangxian...@chromium.org

Comment #18 on issue 141840 by ael...@chromium.org:
document.elementFromPoint returns a wrong element
http://code.google.com/p/chromium/issues/detail?id=141840

Tien-Ren can look at this.

chro...@googlecode.com

unread,
Oct 25, 2012, 9:09:50 PM10/25/12
to chromi...@chromium.org

Comment #19 on issue 141840 by knunn...@gmail.com:
document.elementFromPoint returns a wrong element
http://code.google.com/p/chromium/issues/detail?id=141840

As mentioned in my original comment, a foolproof workaround for this issue
is:

document.elementFromPoint(event.changedTouches[0].screenX,
event.changedTouches[0].screenY);

as put to use in: https://dev-app.thelockerproject.com/Scripts/touchfix.js

Ironically this fix is being used because event.target is also broken, and
this is a fix for it.

chro...@googlecode.com

unread,
Nov 9, 2012, 5:55:46 PM11/9/12
to chromi...@chromium.org

Comment #20 on issue 141840 by trc...@chromium.org:
document.elementFromPoint returns a wrong element
http://code.google.com/p/chromium/issues/detail?id=141840

Fix pending:
https://bugs.webkit.org/show_bug.cgi?id=101798
https://bugs.webkit.org/show_bug.cgi?id=101800

The use of touchEvent.screenX/Y is incorrect. Although we currently pass
clientX/Y in physical pixel as screenX/Y, this behavior may change in the
future.

Most of the coordinates used in JavaScript will be in client coordinate,
that is, the position related to the viewport (scroll offset excluded) and
in document pixels (without page scale factor multiplied). The above
patches correct the behavior.

chro...@googlecode.com

unread,
Nov 9, 2012, 8:20:46 PM11/9/12
to chromi...@chromium.org
Updates:
Status: Fixed

Comment #21 on issue 141840 by trc...@chromium.org:
document.elementFromPoint returns a wrong element
http://code.google.com/p/chromium/issues/detail?id=141840

All reviewed patches have been landed. Closing bug.

chro...@googlecode.com

unread,
Dec 13, 2012, 4:23:33 AM12/13/12
to chromi...@chromium.org

Comment #22 on issue 141840 by riofr...@gmail.com:
document.elementFromPoint returns a wrong element
http://code.google.com/p/chromium/issues/detail?id=141840

This bug is still present on the latest stable Chrome for Android 18. Which
version will this fix land on?

chro...@googlecode.com

unread,
Dec 13, 2012, 7:29:51 PM12/13/12
to chromi...@chromium.org

Comment #24 on issue 141840 by simon.sa...@gmail.com:
document.elementFromPoint returns a wrong element
http://code.google.com/p/chromium/issues/detail?id=141840

Is this bug related to the clientX/clientY bug, here?

https://code.google.com/p/chromium/issues/detail?id=117754

If so, that one ought to mention this topic and be closed as well.

chro...@googlecode.com

unread,
Dec 13, 2012, 7:50:51 PM12/13/12
to chromi...@chromium.org

Comment #25 on issue 141840 by trc...@chromium.org:
document.elementFromPoint returns a wrong element
http://code.google.com/p/chromium/issues/detail?id=141840

Issue 117754 has been merged into this issue.

chro...@googlecode.com

unread,
Dec 13, 2012, 7:53:51 PM12/13/12
to chromi...@chromium.org

Comment #26 on issue 141840 by trc...@chromium.org:

chro...@googlecode.com

unread,
Jan 4, 2013, 7:47:42 AM1/4/13
to chromi...@chromium.org

Comment #27 on issue 141840 by stevenlu...@gmail.com:
document.elementFromPoint returns a wrong element
http://code.google.com/p/chromium/issues/detail?id=141840

When will this fix be available? (I have a Nexus 7)

Is there a JS workaround that will not be re-broken once the fix lands? (If
no, I should leave it (since I got it perfect on iOS) and then hopefully in
a few days it will magically be correct)

Reply all
Reply to author
Forward
0 new messages