diff --git a/dist/autofill-debug.js b/dist/autofill-debug.js index bf454e853..5fb3287fd 100644 --- a/dist/autofill-debug.js +++ b/dist/autofill-debug.js @@ -11006,15 +11006,19 @@ class FormAnalyzer { } /** - * Checks if the element is present in the cusotm elements registry and ends with a '-link' suffix. - * If it does, it checks if it contains an anchor element inside. + * Function that checks if the element is an external link or a custom web element that + * encapsulates a link. * @param {any} el - * @returns + * @returns {boolean} */ - isCustomWebElementLink(el) { + isElementExternalLink(el) { + // Checks if the element is present in the cusotm elements registry and ends with a '-link' suffix. + // If it does, it checks if it contains an anchor element inside. const tagName = el.nodeName.toLowerCase(); - const isCustomElement = customElements != null && customElements.get(tagName) != null; - return isCustomElement && /-link$/.test(tagName) && (0, _autofillUtils.findElementsInShadowTree)(el, 'a').length > 0; + const isCustomWebElementLink = customElements.get(tagName) != null && /-link$/.test(tagName) && (0, _autofillUtils.findElementsInShadowTree)(el, 'a').length > 0; + + // if an external link matches one of the regexes, we assume the match is not pertinent to the current form + return el instanceof HTMLAnchorElement && el.href && el.getAttribute('href') !== '#' || (el.getAttribute('role') || '').toUpperCase() === 'LINK' || el.matches('button[class*=secondary]') || isCustomWebElementLink; } evaluateElement(el) { const string = (0, _autofillUtils.getTextShallow)(el); @@ -11055,8 +11059,7 @@ class FormAnalyzer { }); return; } - // if an external link matches one of the regexes, we assume the match is not pertinent to the current form - if (el instanceof HTMLAnchorElement && el.href && el.getAttribute('href') !== '#' || (el.getAttribute('role') || '').toUpperCase() === 'LINK' || el.matches('button[class*=secondary]') || this.isCustomWebElementLink(el)) { + if (this.isElementExternalLink(el)) { let shouldFlip = true; let strength = 1; // Don't flip forgotten password links @@ -14644,7 +14647,7 @@ class DefaultScanner { } if (element.parentElement) { element = element.parentElement; - // check if current element is the only child of the parent, and increase traversal only then + // If the parent is a redundant component (only contains a single element or is a shadowRoot) do not increase the traversal count. if (element.childElementCount > 1) { const inputs = element.querySelectorAll(this.matching.cssSelector('formInputsSelector')); const buttons = element.querySelectorAll(this.matching.cssSelector('submitButtonSelector')); diff --git a/dist/autofill.js b/dist/autofill.js index 8532a294e..9c029552a 100644 --- a/dist/autofill.js +++ b/dist/autofill.js @@ -6840,15 +6840,19 @@ class FormAnalyzer { } /** - * Checks if the element is present in the cusotm elements registry and ends with a '-link' suffix. - * If it does, it checks if it contains an anchor element inside. + * Function that checks if the element is an external link or a custom web element that + * encapsulates a link. * @param {any} el - * @returns + * @returns {boolean} */ - isCustomWebElementLink(el) { + isElementExternalLink(el) { + // Checks if the element is present in the cusotm elements registry and ends with a '-link' suffix. + // If it does, it checks if it contains an anchor element inside. const tagName = el.nodeName.toLowerCase(); - const isCustomElement = customElements != null && customElements.get(tagName) != null; - return isCustomElement && /-link$/.test(tagName) && (0, _autofillUtils.findElementsInShadowTree)(el, 'a').length > 0; + const isCustomWebElementLink = customElements.get(tagName) != null && /-link$/.test(tagName) && (0, _autofillUtils.findElementsInShadowTree)(el, 'a').length > 0; + + // if an external link matches one of the regexes, we assume the match is not pertinent to the current form + return el instanceof HTMLAnchorElement && el.href && el.getAttribute('href') !== '#' || (el.getAttribute('role') || '').toUpperCase() === 'LINK' || el.matches('button[class*=secondary]') || isCustomWebElementLink; } evaluateElement(el) { const string = (0, _autofillUtils.getTextShallow)(el); @@ -6889,8 +6893,7 @@ class FormAnalyzer { }); return; } - // if an external link matches one of the regexes, we assume the match is not pertinent to the current form - if (el instanceof HTMLAnchorElement && el.href && el.getAttribute('href') !== '#' || (el.getAttribute('role') || '').toUpperCase() === 'LINK' || el.matches('button[class*=secondary]') || this.isCustomWebElementLink(el)) { + if (this.isElementExternalLink(el)) { let shouldFlip = true; let strength = 1; // Don't flip forgotten password links @@ -10478,7 +10481,7 @@ class DefaultScanner { } if (element.parentElement) { element = element.parentElement; - // check if current element is the only child of the parent, and increase traversal only then + // If the parent is a redundant component (only contains a single element or is a shadowRoot) do not increase the traversal count. if (element.childElementCount > 1) { const inputs = element.querySelectorAll(this.matching.cssSelector('formInputsSelector')); const buttons = element.querySelectorAll(this.matching.cssSelector('submitButtonSelector')); diff --git a/src/Form/FormAnalyzer.js b/src/Form/FormAnalyzer.js index ab6c58da4..0deac1c83 100644 --- a/src/Form/FormAnalyzer.js +++ b/src/Form/FormAnalyzer.js @@ -224,15 +224,25 @@ class FormAnalyzer { } /** - * Checks if the element is present in the cusotm elements registry and ends with a '-link' suffix. - * If it does, it checks if it contains an anchor element inside. + * Function that checks if the element is an external link or a custom web element that + * encapsulates a link. * @param {any} el - * @returns + * @returns {boolean} */ - isCustomWebElementLink(el) { + isElementExternalLink(el) { + // Checks if the element is present in the cusotm elements registry and ends with a '-link' suffix. + // If it does, it checks if it contains an anchor element inside. const tagName = el.nodeName.toLowerCase(); - const isCustomElement = customElements != null && customElements.get(tagName) != null; - return isCustomElement && /-link$/.test(tagName) && findElementsInShadowTree(el, 'a').length > 0; + const isCustomWebElementLink = + customElements.get(tagName) != null && /-link$/.test(tagName) && findElementsInShadowTree(el, 'a').length > 0; + + // if an external link matches one of the regexes, we assume the match is not pertinent to the current form + return ( + (el instanceof HTMLAnchorElement && el.href && el.getAttribute('href') !== '#') || + (el.getAttribute('role') || '').toUpperCase() === 'LINK' || + el.matches('button[class*=secondary]') || + isCustomWebElementLink + ); } evaluateElement(el) { @@ -270,13 +280,7 @@ class FormAnalyzer { this.updateSignal({ string, strength, signalType: `button: ${string}`, shouldFlip }); return; } - // if an external link matches one of the regexes, we assume the match is not pertinent to the current form - if ( - (el instanceof HTMLAnchorElement && el.href && el.getAttribute('href') !== '#') || - (el.getAttribute('role') || '').toUpperCase() === 'LINK' || - el.matches('button[class*=secondary]') || - this.isCustomWebElementLink(el) - ) { + if (this.isElementExternalLink(el)) { let shouldFlip = true; let strength = 1; // Don't flip forgotten password links diff --git a/src/Scanner.js b/src/Scanner.js index b46790d2d..49f51c10d 100644 --- a/src/Scanner.js +++ b/src/Scanner.js @@ -252,7 +252,7 @@ class DefaultScanner { if (element.parentElement) { element = element.parentElement; - // check if current element is the only child of the parent, and increase traversal only then + // If the parent is a redundant component (only contains a single element or is a shadowRoot) do not increase the traversal count. if (element.childElementCount > 1) { const inputs = element.querySelectorAll(this.matching.cssSelector('formInputsSelector')); const buttons = element.querySelectorAll(this.matching.cssSelector('submitButtonSelector')); diff --git a/swift-package/Resources/assets/autofill-debug.js b/swift-package/Resources/assets/autofill-debug.js index bf454e853..5fb3287fd 100644 --- a/swift-package/Resources/assets/autofill-debug.js +++ b/swift-package/Resources/assets/autofill-debug.js @@ -11006,15 +11006,19 @@ class FormAnalyzer { } /** - * Checks if the element is present in the cusotm elements registry and ends with a '-link' suffix. - * If it does, it checks if it contains an anchor element inside. + * Function that checks if the element is an external link or a custom web element that + * encapsulates a link. * @param {any} el - * @returns + * @returns {boolean} */ - isCustomWebElementLink(el) { + isElementExternalLink(el) { + // Checks if the element is present in the cusotm elements registry and ends with a '-link' suffix. + // If it does, it checks if it contains an anchor element inside. const tagName = el.nodeName.toLowerCase(); - const isCustomElement = customElements != null && customElements.get(tagName) != null; - return isCustomElement && /-link$/.test(tagName) && (0, _autofillUtils.findElementsInShadowTree)(el, 'a').length > 0; + const isCustomWebElementLink = customElements.get(tagName) != null && /-link$/.test(tagName) && (0, _autofillUtils.findElementsInShadowTree)(el, 'a').length > 0; + + // if an external link matches one of the regexes, we assume the match is not pertinent to the current form + return el instanceof HTMLAnchorElement && el.href && el.getAttribute('href') !== '#' || (el.getAttribute('role') || '').toUpperCase() === 'LINK' || el.matches('button[class*=secondary]') || isCustomWebElementLink; } evaluateElement(el) { const string = (0, _autofillUtils.getTextShallow)(el); @@ -11055,8 +11059,7 @@ class FormAnalyzer { }); return; } - // if an external link matches one of the regexes, we assume the match is not pertinent to the current form - if (el instanceof HTMLAnchorElement && el.href && el.getAttribute('href') !== '#' || (el.getAttribute('role') || '').toUpperCase() === 'LINK' || el.matches('button[class*=secondary]') || this.isCustomWebElementLink(el)) { + if (this.isElementExternalLink(el)) { let shouldFlip = true; let strength = 1; // Don't flip forgotten password links @@ -14644,7 +14647,7 @@ class DefaultScanner { } if (element.parentElement) { element = element.parentElement; - // check if current element is the only child of the parent, and increase traversal only then + // If the parent is a redundant component (only contains a single element or is a shadowRoot) do not increase the traversal count. if (element.childElementCount > 1) { const inputs = element.querySelectorAll(this.matching.cssSelector('formInputsSelector')); const buttons = element.querySelectorAll(this.matching.cssSelector('submitButtonSelector')); diff --git a/swift-package/Resources/assets/autofill.js b/swift-package/Resources/assets/autofill.js index 8532a294e..9c029552a 100644 --- a/swift-package/Resources/assets/autofill.js +++ b/swift-package/Resources/assets/autofill.js @@ -6840,15 +6840,19 @@ class FormAnalyzer { } /** - * Checks if the element is present in the cusotm elements registry and ends with a '-link' suffix. - * If it does, it checks if it contains an anchor element inside. + * Function that checks if the element is an external link or a custom web element that + * encapsulates a link. * @param {any} el - * @returns + * @returns {boolean} */ - isCustomWebElementLink(el) { + isElementExternalLink(el) { + // Checks if the element is present in the cusotm elements registry and ends with a '-link' suffix. + // If it does, it checks if it contains an anchor element inside. const tagName = el.nodeName.toLowerCase(); - const isCustomElement = customElements != null && customElements.get(tagName) != null; - return isCustomElement && /-link$/.test(tagName) && (0, _autofillUtils.findElementsInShadowTree)(el, 'a').length > 0; + const isCustomWebElementLink = customElements.get(tagName) != null && /-link$/.test(tagName) && (0, _autofillUtils.findElementsInShadowTree)(el, 'a').length > 0; + + // if an external link matches one of the regexes, we assume the match is not pertinent to the current form + return el instanceof HTMLAnchorElement && el.href && el.getAttribute('href') !== '#' || (el.getAttribute('role') || '').toUpperCase() === 'LINK' || el.matches('button[class*=secondary]') || isCustomWebElementLink; } evaluateElement(el) { const string = (0, _autofillUtils.getTextShallow)(el); @@ -6889,8 +6893,7 @@ class FormAnalyzer { }); return; } - // if an external link matches one of the regexes, we assume the match is not pertinent to the current form - if (el instanceof HTMLAnchorElement && el.href && el.getAttribute('href') !== '#' || (el.getAttribute('role') || '').toUpperCase() === 'LINK' || el.matches('button[class*=secondary]') || this.isCustomWebElementLink(el)) { + if (this.isElementExternalLink(el)) { let shouldFlip = true; let strength = 1; // Don't flip forgotten password links @@ -10478,7 +10481,7 @@ class DefaultScanner { } if (element.parentElement) { element = element.parentElement; - // check if current element is the only child of the parent, and increase traversal only then + // If the parent is a redundant component (only contains a single element or is a shadowRoot) do not increase the traversal count. if (element.childElementCount > 1) { const inputs = element.querySelectorAll(this.matching.cssSelector('formInputsSelector')); const buttons = element.querySelectorAll(this.matching.cssSelector('submitButtonSelector'));