diff --git a/dist/autofill-debug.js b/dist/autofill-debug.js index 89295c5b9..88cd634b7 100644 --- a/dist/autofill-debug.js +++ b/dist/autofill-debug.js @@ -11198,10 +11198,14 @@ class FormAnalyzer { // If it does, it checks if it contains an anchor element inside. const tagName = el.nodeName.toLowerCase(); 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 - const isElementLink = el instanceof HTMLAnchorElement && el.href && el.getAttribute('href') !== '#' || (el.getAttribute('role') || '').toUpperCase() === 'LINK' || el.matches('button[class*=secondary]'); - return isCustomWebElementLink || isElementLink; + const isElementLink = element => { + // if an external link matches one of the regexes, we assume the match is not pertinent to the current form + if (element instanceof HTMLAnchorElement) { + return element.href && element.getAttribute('href') !== '#' || (element.getAttribute('role') || '').toUpperCase() === 'LINK' || element.matches('button[class*=secondary]'); + } + return false; + }; + return isCustomWebElementLink || isElementLink(el) || isElementLink(el.closest('a')); } evaluateElement(el) { const string = (0, _autofillUtils.getTextShallow)(el); @@ -11231,7 +11235,7 @@ class FormAnalyzer { // Here we don't think this is a submit, so if there is another submit in the form, flip the score const thereIsASubmitButton = Boolean(this.form.querySelector('input[type=submit], button[type=submit]')); const isSocialButton = /facebook|twitter|google|apple/i.test(string); - shouldFlip = thereIsASubmitButton && !isSocialButton; + shouldFlip = !isSocialButton && (this.isElementExternalLink(el) || thereIsASubmitButton); } const strength = likelyASubmit ? 20 : 4; this.updateSignal({ diff --git a/src/Form/FormAnalyzer.js b/src/Form/FormAnalyzer.js index 8635bacaf..b19832250 100644 --- a/src/Form/FormAnalyzer.js +++ b/src/Form/FormAnalyzer.js @@ -243,13 +243,19 @@ class FormAnalyzer { 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 - const isElementLink = - (el instanceof HTMLAnchorElement && el.href && el.getAttribute('href') !== '#') || - (el.getAttribute('role') || '').toUpperCase() === 'LINK' || - el.matches('button[class*=secondary]'); + const isElementLink = (element) => { + // if an external link matches one of the regexes, we assume the match is not pertinent to the current form + if (element instanceof HTMLAnchorElement) { + return ( + (element.href && element.getAttribute('href') !== '#') || + (element.getAttribute('role') || '').toUpperCase() === 'LINK' || + element.matches('button[class*=secondary]') + ); + } + return false; + }; - return isCustomWebElementLink || isElementLink; + return isCustomWebElementLink || isElementLink(el) || isElementLink(el.closest('a')); } evaluateElement(el) { @@ -281,7 +287,7 @@ class FormAnalyzer { // Here we don't think this is a submit, so if there is another submit in the form, flip the score const thereIsASubmitButton = Boolean(this.form.querySelector('input[type=submit], button[type=submit]')); const isSocialButton = /facebook|twitter|google|apple/i.test(string); - shouldFlip = thereIsASubmitButton && !isSocialButton; + shouldFlip = !isSocialButton && (this.isElementExternalLink(el) || thereIsASubmitButton); } const strength = likelyASubmit ? 20 : 4; this.updateSignal({ string, strength, signalType: `button: ${string}`, shouldFlip }); diff --git a/swift-package/Resources/assets/autofill-debug.js b/swift-package/Resources/assets/autofill-debug.js index 89295c5b9..88cd634b7 100644 --- a/swift-package/Resources/assets/autofill-debug.js +++ b/swift-package/Resources/assets/autofill-debug.js @@ -11198,10 +11198,14 @@ class FormAnalyzer { // If it does, it checks if it contains an anchor element inside. const tagName = el.nodeName.toLowerCase(); 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 - const isElementLink = el instanceof HTMLAnchorElement && el.href && el.getAttribute('href') !== '#' || (el.getAttribute('role') || '').toUpperCase() === 'LINK' || el.matches('button[class*=secondary]'); - return isCustomWebElementLink || isElementLink; + const isElementLink = element => { + // if an external link matches one of the regexes, we assume the match is not pertinent to the current form + if (element instanceof HTMLAnchorElement) { + return element.href && element.getAttribute('href') !== '#' || (element.getAttribute('role') || '').toUpperCase() === 'LINK' || element.matches('button[class*=secondary]'); + } + return false; + }; + return isCustomWebElementLink || isElementLink(el) || isElementLink(el.closest('a')); } evaluateElement(el) { const string = (0, _autofillUtils.getTextShallow)(el); @@ -11231,7 +11235,7 @@ class FormAnalyzer { // Here we don't think this is a submit, so if there is another submit in the form, flip the score const thereIsASubmitButton = Boolean(this.form.querySelector('input[type=submit], button[type=submit]')); const isSocialButton = /facebook|twitter|google|apple/i.test(string); - shouldFlip = thereIsASubmitButton && !isSocialButton; + shouldFlip = !isSocialButton && (this.isElementExternalLink(el) || thereIsASubmitButton); } const strength = likelyASubmit ? 20 : 4; this.updateSignal({