From 5d30d7ee8a2d49978481b99885535765f7a79f75 Mon Sep 17 00:00:00 2001 From: dbajpeyi Date: Thu, 28 Nov 2024 12:00:54 +0100 Subject: [PATCH 1/3] fix: check if texts are wrapped in buttons --- dist/autofill-debug.js | 6 +++- dist/autofill.js | 6 +++- src/Form/FormAnalyzer.js | 11 +++--- .../Resources/assets/autofill-debug.js | 6 +++- swift-package/Resources/assets/autofill.js | 6 +++- test-forms/index.json | 4 +-- test-forms/paperlesspost_login.html | 36 +++++++++++++++++++ 7 files changed, 65 insertions(+), 10 deletions(-) create mode 100644 test-forms/paperlesspost_login.html diff --git a/dist/autofill-debug.js b/dist/autofill-debug.js index 06004d529..11542f3b2 100644 --- a/dist/autofill-debug.js +++ b/dist/autofill-debug.js @@ -10996,8 +10996,12 @@ class FormAnalyzer { const tagName = el.nodeName.toLowerCase(); const isCustomWebElementLink = customElements?.get(tagName) != null && /-link$/.test(tagName) && (0, _autofillUtils.findElementsInShadowTree)(el, 'a').length > 0; + // Checks if the element is wrapped in an anchor or button element. We check only one level deep to avoid performance issues. + const isWrappedInLink = el.parentElement instanceof HTMLAnchorElement || el.parentElement instanceof HTMLButtonElement; + // 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; + const isElementLink = el instanceof HTMLAnchorElement && el.href && el.getAttribute('href') !== '#' || (el.getAttribute('role') || '').toUpperCase() === 'LINK' || el.matches('button[class*=secondary]'); + return isCustomWebElementLink || isWrappedInLink || isElementLink; } evaluateElement(el) { const string = (0, _autofillUtils.getTextShallow)(el); diff --git a/dist/autofill.js b/dist/autofill.js index b3e874725..511e44498 100644 --- a/dist/autofill.js +++ b/dist/autofill.js @@ -6830,8 +6830,12 @@ class FormAnalyzer { const tagName = el.nodeName.toLowerCase(); const isCustomWebElementLink = customElements?.get(tagName) != null && /-link$/.test(tagName) && (0, _autofillUtils.findElementsInShadowTree)(el, 'a').length > 0; + // Checks if the element is wrapped in an anchor or button element. We check only one level deep to avoid performance issues. + const isWrappedInLink = el.parentElement instanceof HTMLAnchorElement || el.parentElement instanceof HTMLButtonElement; + // 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; + const isElementLink = el instanceof HTMLAnchorElement && el.href && el.getAttribute('href') !== '#' || (el.getAttribute('role') || '').toUpperCase() === 'LINK' || el.matches('button[class*=secondary]'); + return isCustomWebElementLink || isWrappedInLink || isElementLink; } evaluateElement(el) { const string = (0, _autofillUtils.getTextShallow)(el); diff --git a/src/Form/FormAnalyzer.js b/src/Form/FormAnalyzer.js index 7f1acebe6..011c87770 100644 --- a/src/Form/FormAnalyzer.js +++ b/src/Form/FormAnalyzer.js @@ -242,13 +242,16 @@ class FormAnalyzer { const isCustomWebElementLink = customElements?.get(tagName) != null && /-link$/.test(tagName) && findElementsInShadowTree(el, 'a').length > 0; + // Checks if the element is wrapped in an anchor or button element. We check only one level deep to avoid performance issues. + const isWrappedInLink = el.parentElement instanceof HTMLAnchorElement || el.parentElement instanceof HTMLButtonElement; + // if an external link matches one of the regexes, we assume the match is not pertinent to the current form - return ( + const isElementLink = (el instanceof HTMLAnchorElement && el.href && el.getAttribute('href') !== '#') || (el.getAttribute('role') || '').toUpperCase() === 'LINK' || - el.matches('button[class*=secondary]') || - isCustomWebElementLink - ); + el.matches('button[class*=secondary]'); + + return isCustomWebElementLink || isWrappedInLink || isElementLink; } evaluateElement(el) { diff --git a/swift-package/Resources/assets/autofill-debug.js b/swift-package/Resources/assets/autofill-debug.js index 06004d529..11542f3b2 100644 --- a/swift-package/Resources/assets/autofill-debug.js +++ b/swift-package/Resources/assets/autofill-debug.js @@ -10996,8 +10996,12 @@ class FormAnalyzer { const tagName = el.nodeName.toLowerCase(); const isCustomWebElementLink = customElements?.get(tagName) != null && /-link$/.test(tagName) && (0, _autofillUtils.findElementsInShadowTree)(el, 'a').length > 0; + // Checks if the element is wrapped in an anchor or button element. We check only one level deep to avoid performance issues. + const isWrappedInLink = el.parentElement instanceof HTMLAnchorElement || el.parentElement instanceof HTMLButtonElement; + // 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; + const isElementLink = el instanceof HTMLAnchorElement && el.href && el.getAttribute('href') !== '#' || (el.getAttribute('role') || '').toUpperCase() === 'LINK' || el.matches('button[class*=secondary]'); + return isCustomWebElementLink || isWrappedInLink || isElementLink; } evaluateElement(el) { const string = (0, _autofillUtils.getTextShallow)(el); diff --git a/swift-package/Resources/assets/autofill.js b/swift-package/Resources/assets/autofill.js index b3e874725..511e44498 100644 --- a/swift-package/Resources/assets/autofill.js +++ b/swift-package/Resources/assets/autofill.js @@ -6830,8 +6830,12 @@ class FormAnalyzer { const tagName = el.nodeName.toLowerCase(); const isCustomWebElementLink = customElements?.get(tagName) != null && /-link$/.test(tagName) && (0, _autofillUtils.findElementsInShadowTree)(el, 'a').length > 0; + // Checks if the element is wrapped in an anchor or button element. We check only one level deep to avoid performance issues. + const isWrappedInLink = el.parentElement instanceof HTMLAnchorElement || el.parentElement instanceof HTMLButtonElement; + // 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; + const isElementLink = el instanceof HTMLAnchorElement && el.href && el.getAttribute('href') !== '#' || (el.getAttribute('role') || '').toUpperCase() === 'LINK' || el.matches('button[class*=secondary]'); + return isCustomWebElementLink || isWrappedInLink || isElementLink; } evaluateElement(el) { const string = (0, _autofillUtils.getTextShallow)(el); diff --git a/test-forms/index.json b/test-forms/index.json index 33b89c3b8..cbc1de347 100644 --- a/test-forms/index.json +++ b/test-forms/index.json @@ -546,6 +546,6 @@ { "html": "single-select-form.html" }, { "html": "camelcamelcamel_login.html" }, { "html": "accounts_oneplus_login.html"}, - { "html": "google_password_manager_search.html"} - + { "html": "google_password_manager_search.html"}, + { "html": "paperlesspost_login.html"} ] diff --git a/test-forms/paperlesspost_login.html b/test-forms/paperlesspost_login.html new file mode 100644 index 000000000..75e834a5d --- /dev/null +++ b/test-forms/paperlesspost_login.html @@ -0,0 +1,36 @@ +
+ + + Google logo + + + + + + + + Log in with Google + + + + Facebook icon + + + Log in with Facebook + + + + Apple logo + + + Log in with Apple + + +
+ +
\ No newline at end of file From edb57e350f9c8adbeeed99b98876d64196084479 Mon Sep 17 00:00:00 2001 From: dbajpeyi Date: Thu, 28 Nov 2024 14:27:50 +0100 Subject: [PATCH 2/3] fix: check if submit attribute was explicitly --- dist/autofill-debug.js | 2 +- dist/autofill.js | 2 +- src/Form/FormAnalyzer.js | 2 +- swift-package/Resources/assets/autofill-debug.js | 2 +- swift-package/Resources/assets/autofill.js | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/dist/autofill-debug.js b/dist/autofill-debug.js index 11542f3b2..a897e7bcb 100644 --- a/dist/autofill-debug.js +++ b/dist/autofill-debug.js @@ -11023,7 +11023,7 @@ class FormAnalyzer { if (likelyASubmit) { this.form.querySelectorAll('input[type=submit], button[type=submit]').forEach(submit => { // If there is another element marked as submit and this is not, flip back to false - if (el.type !== 'submit' && el !== submit) { + if (el.getAttribute('type') !== 'submit' && el !== submit) { likelyASubmit = false; } }); diff --git a/dist/autofill.js b/dist/autofill.js index 511e44498..ced0ae1d3 100644 --- a/dist/autofill.js +++ b/dist/autofill.js @@ -6857,7 +6857,7 @@ class FormAnalyzer { if (likelyASubmit) { this.form.querySelectorAll('input[type=submit], button[type=submit]').forEach(submit => { // If there is another element marked as submit and this is not, flip back to false - if (el.type !== 'submit' && el !== submit) { + if (el.getAttribute('type') !== 'submit' && el !== submit) { likelyASubmit = false; } }); diff --git a/src/Form/FormAnalyzer.js b/src/Form/FormAnalyzer.js index 011c87770..f65a9c2fc 100644 --- a/src/Form/FormAnalyzer.js +++ b/src/Form/FormAnalyzer.js @@ -275,7 +275,7 @@ class FormAnalyzer { if (likelyASubmit) { this.form.querySelectorAll('input[type=submit], button[type=submit]').forEach((submit) => { // If there is another element marked as submit and this is not, flip back to false - if (el.type !== 'submit' && el !== submit) { + if (el.getAttribute('type') !== 'submit' && el !== submit) { likelyASubmit = false; } }); diff --git a/swift-package/Resources/assets/autofill-debug.js b/swift-package/Resources/assets/autofill-debug.js index 11542f3b2..a897e7bcb 100644 --- a/swift-package/Resources/assets/autofill-debug.js +++ b/swift-package/Resources/assets/autofill-debug.js @@ -11023,7 +11023,7 @@ class FormAnalyzer { if (likelyASubmit) { this.form.querySelectorAll('input[type=submit], button[type=submit]').forEach(submit => { // If there is another element marked as submit and this is not, flip back to false - if (el.type !== 'submit' && el !== submit) { + if (el.getAttribute('type') !== 'submit' && el !== submit) { likelyASubmit = false; } }); diff --git a/swift-package/Resources/assets/autofill.js b/swift-package/Resources/assets/autofill.js index 511e44498..ced0ae1d3 100644 --- a/swift-package/Resources/assets/autofill.js +++ b/swift-package/Resources/assets/autofill.js @@ -6857,7 +6857,7 @@ class FormAnalyzer { if (likelyASubmit) { this.form.querySelectorAll('input[type=submit], button[type=submit]').forEach(submit => { // If there is another element marked as submit and this is not, flip back to false - if (el.type !== 'submit' && el !== submit) { + if (el.getAttribute('type') !== 'submit' && el !== submit) { likelyASubmit = false; } }); From c9ebdb783f00d31898f3c4205e20ae51d79ff740 Mon Sep 17 00:00:00 2001 From: dbajpeyi Date: Thu, 28 Nov 2024 14:55:46 +0100 Subject: [PATCH 3/3] revert: don't check for parent external link --- dist/autofill-debug.js | 5 +---- dist/autofill.js | 5 +---- src/Form/FormAnalyzer.js | 5 +---- swift-package/Resources/assets/autofill-debug.js | 5 +---- swift-package/Resources/assets/autofill.js | 5 +---- 5 files changed, 5 insertions(+), 20 deletions(-) diff --git a/dist/autofill-debug.js b/dist/autofill-debug.js index a897e7bcb..ef7822212 100644 --- a/dist/autofill-debug.js +++ b/dist/autofill-debug.js @@ -10996,12 +10996,9 @@ class FormAnalyzer { const tagName = el.nodeName.toLowerCase(); const isCustomWebElementLink = customElements?.get(tagName) != null && /-link$/.test(tagName) && (0, _autofillUtils.findElementsInShadowTree)(el, 'a').length > 0; - // Checks if the element is wrapped in an anchor or button element. We check only one level deep to avoid performance issues. - const isWrappedInLink = el.parentElement instanceof HTMLAnchorElement || el.parentElement instanceof HTMLButtonElement; - // 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 || isWrappedInLink || isElementLink; + return isCustomWebElementLink || isElementLink; } evaluateElement(el) { const string = (0, _autofillUtils.getTextShallow)(el); diff --git a/dist/autofill.js b/dist/autofill.js index ced0ae1d3..26fc5d88b 100644 --- a/dist/autofill.js +++ b/dist/autofill.js @@ -6830,12 +6830,9 @@ class FormAnalyzer { const tagName = el.nodeName.toLowerCase(); const isCustomWebElementLink = customElements?.get(tagName) != null && /-link$/.test(tagName) && (0, _autofillUtils.findElementsInShadowTree)(el, 'a').length > 0; - // Checks if the element is wrapped in an anchor or button element. We check only one level deep to avoid performance issues. - const isWrappedInLink = el.parentElement instanceof HTMLAnchorElement || el.parentElement instanceof HTMLButtonElement; - // 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 || isWrappedInLink || isElementLink; + return isCustomWebElementLink || isElementLink; } evaluateElement(el) { const string = (0, _autofillUtils.getTextShallow)(el); diff --git a/src/Form/FormAnalyzer.js b/src/Form/FormAnalyzer.js index f65a9c2fc..77647b70d 100644 --- a/src/Form/FormAnalyzer.js +++ b/src/Form/FormAnalyzer.js @@ -242,16 +242,13 @@ class FormAnalyzer { const isCustomWebElementLink = customElements?.get(tagName) != null && /-link$/.test(tagName) && findElementsInShadowTree(el, 'a').length > 0; - // Checks if the element is wrapped in an anchor or button element. We check only one level deep to avoid performance issues. - const isWrappedInLink = el.parentElement instanceof HTMLAnchorElement || el.parentElement instanceof HTMLButtonElement; - // 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 || isWrappedInLink || isElementLink; + return isCustomWebElementLink || isElementLink; } evaluateElement(el) { diff --git a/swift-package/Resources/assets/autofill-debug.js b/swift-package/Resources/assets/autofill-debug.js index a897e7bcb..ef7822212 100644 --- a/swift-package/Resources/assets/autofill-debug.js +++ b/swift-package/Resources/assets/autofill-debug.js @@ -10996,12 +10996,9 @@ class FormAnalyzer { const tagName = el.nodeName.toLowerCase(); const isCustomWebElementLink = customElements?.get(tagName) != null && /-link$/.test(tagName) && (0, _autofillUtils.findElementsInShadowTree)(el, 'a').length > 0; - // Checks if the element is wrapped in an anchor or button element. We check only one level deep to avoid performance issues. - const isWrappedInLink = el.parentElement instanceof HTMLAnchorElement || el.parentElement instanceof HTMLButtonElement; - // 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 || isWrappedInLink || isElementLink; + return isCustomWebElementLink || isElementLink; } evaluateElement(el) { const string = (0, _autofillUtils.getTextShallow)(el); diff --git a/swift-package/Resources/assets/autofill.js b/swift-package/Resources/assets/autofill.js index ced0ae1d3..26fc5d88b 100644 --- a/swift-package/Resources/assets/autofill.js +++ b/swift-package/Resources/assets/autofill.js @@ -6830,12 +6830,9 @@ class FormAnalyzer { const tagName = el.nodeName.toLowerCase(); const isCustomWebElementLink = customElements?.get(tagName) != null && /-link$/.test(tagName) && (0, _autofillUtils.findElementsInShadowTree)(el, 'a').length > 0; - // Checks if the element is wrapped in an anchor or button element. We check only one level deep to avoid performance issues. - const isWrappedInLink = el.parentElement instanceof HTMLAnchorElement || el.parentElement instanceof HTMLButtonElement; - // 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 || isWrappedInLink || isElementLink; + return isCustomWebElementLink || isElementLink; } evaluateElement(el) { const string = (0, _autofillUtils.getTextShallow)(el);