Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Prevent color rules from crashing Chrome 66 #856 #861

Merged
merged 1 commit into from
Apr 24, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 => dom.getRootNode(nodes) === 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