Commit 33345ee5 authored by Shengfa Lin's avatar Shengfa Lin Committed by Chromium LUCI CQ

[chromedriver] Handle shadow root in GetElementLocation

Previously, inView in GetElementLocation only checks for elements
directly under document to see if the point includes the element
under document. However, this does not handle element in shadow DOM.
The change is to check shadow root includes the element at the point
traversing all the way up to document.

Bug: chromedriver:3708
Change-Id: I78cafc847fee3ec4ad850cfaaea66b2f301aa600
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2638653Reviewed-by: default avatarJohn Chen <johnchen@chromium.org>
Commit-Queue: Shengfa Lin <shengfa@google.com>
Cr-Commit-Position: refs/heads/master@{#845215}
parent 6d8c17f1
......@@ -115,14 +115,26 @@ function getInViewPoint(element) {
return [x, y, left, top];
}
function rootNodeIncludes(element, elementPoint) {
if (!element)
return false;
let rootNode = element.getRootNode();
if (rootNode.elementsFromPoint(elementPoint[0], elementPoint[1])
.includes(element)) {
if (rootNode == document)
return true;
return rootNodeIncludes(rootNode.host, elementPoint);
}
return false;
}
function inView(element) {
var elementPoint = getInViewPoint(element);
if (!elementPoint ||
elementPoint[0] <= 0 || elementPoint[1] <= 0 ||
elementPoint[0] >= window.innerWidth ||
elementPoint[1] >= window.innerHeight ||
!document.elementsFromPoint(elementPoint[0], elementPoint[1])
.includes(element)) {
!rootNodeIncludes(element, elementPoint)) {
return false;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment