Skip to content

Commit

Permalink
fix: Prevent color rules from crashing Chrome 66 #856
Browse files Browse the repository at this point in the history
  • Loading branch information
WilcoFiers committed Apr 24, 2018
1 parent e155bea commit 2de9930
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/commons/dom/shadow-elements-from-point.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@
* @param {Object} [root] Shadow root or document root
* @return {Array}
*/
dom.shadowElementsFromPoint = function(nodeX, nodeY, root = document) {
return root.elementsFromPoint(nodeX, nodeY)
dom.shadowElementsFromPoint = function(nodeX, nodeY, root = document, i=0) {
if (i > 999) {
throw new Error('Infinite loop detected');
}
return Array.from(root.elementsFromPoint(nodeX, nodeY))
// As of Chrome 66, elementFromPoint will return elements from parent trees.
// We only want to touch each tree once, so we're filtering out nodes on other trees.
.filter(nodes => nodes.getRootNode() === root)
.reduce((stack, elm) => {
if (axe.utils.isShadowRoot(elm)) {
const shadowStack = dom.shadowElementsFromPoint(nodeX, nodeY, elm.shadowRoot);
const shadowStack = dom.shadowElementsFromPoint(nodeX, nodeY, elm.shadowRoot, i+1);
stack = stack.concat(shadowStack);
// filter host nodes which get included regardless of overlap
// TODO: refactor multiline overlap checking inside shadow dom
Expand Down

0 comments on commit 2de9930

Please sign in to comment.