diff --git a/dist/autofill-debug.js b/dist/autofill-debug.js index ec650067f..7e2bc6091 100644 --- a/dist/autofill-debug.js +++ b/dist/autofill-debug.js @@ -10219,15 +10219,18 @@ class Form { * If .elements doesn't work, it falls back to querySelectorAll. * Doesn't look for shadow elements. * @param {string} selector - * @returns + * @returns {Element[]} */ getFormElements(selector) { // Some sites seem to be overriding `form.elements`, so we need to check if it's still iterable. + /** @type {Element[]|NodeListOf} element */ + let formElements = []; if (this.form instanceof HTMLFormElement && this.form.elements != null && Symbol.iterator in Object(this.form.elements)) { - return [...this.form.elements].filter(el => el.matches(selector)); + formElements = [...this.form.elements].filter(el => el.matches(selector)); } else { - return this.form.querySelectorAll(selector); + formElements = this.form.querySelectorAll(selector); } + return [...formElements, ...(0, _autofillUtils.findElementsInShadowTree)(this.form, selector)]; } categorizeInputs() { const selector = this.matching.cssSelector('formInputsSelector'); @@ -10236,11 +10239,9 @@ class Form { this.addInput(this.form); } else { /** @type {Element[] | NodeList} */ - let foundInputs = []; - const formElements = this.getFormElements(selector); // Also scan the form for shadow elements - foundInputs = [...formElements, ...(0, _autofillUtils.findElementsInShadowTree)(this.form, selector)]; + const foundInputs = this.getFormElements(selector); if (foundInputs.length < MAX_INPUTS_PER_FORM) { foundInputs.forEach(input => this.addInput(input)); } else { @@ -14828,8 +14829,8 @@ class DefaultScanner { if (realTarget instanceof HTMLInputElement && !realTarget.hasAttribute(ATTR_INPUT_TYPE)) { const parentForm = this.getParentForm(realTarget); - // If the parent form is an input element, we don't want to scan it further - if (parentForm instanceof HTMLInputElement) return; + // If the parent form is an input element or the same as the target, we don't want to scan it further. + if (parentForm instanceof HTMLInputElement || parentForm.isEqualNode(realTarget)) return; const hasShadowTree = event.target?.shadowRoot != null; const form = new _Form.Form(parentForm, realTarget, this.device, this.matching, this.shouldAutoprompt, hasShadowTree); this.forms.set(parentForm, form); diff --git a/dist/autofill.js b/dist/autofill.js index e59cd0080..a5a8edb31 100644 --- a/dist/autofill.js +++ b/dist/autofill.js @@ -6053,15 +6053,18 @@ class Form { * If .elements doesn't work, it falls back to querySelectorAll. * Doesn't look for shadow elements. * @param {string} selector - * @returns + * @returns {Element[]} */ getFormElements(selector) { // Some sites seem to be overriding `form.elements`, so we need to check if it's still iterable. + /** @type {Element[]|NodeListOf} element */ + let formElements = []; if (this.form instanceof HTMLFormElement && this.form.elements != null && Symbol.iterator in Object(this.form.elements)) { - return [...this.form.elements].filter(el => el.matches(selector)); + formElements = [...this.form.elements].filter(el => el.matches(selector)); } else { - return this.form.querySelectorAll(selector); + formElements = this.form.querySelectorAll(selector); } + return [...formElements, ...(0, _autofillUtils.findElementsInShadowTree)(this.form, selector)]; } categorizeInputs() { const selector = this.matching.cssSelector('formInputsSelector'); @@ -6070,11 +6073,9 @@ class Form { this.addInput(this.form); } else { /** @type {Element[] | NodeList} */ - let foundInputs = []; - const formElements = this.getFormElements(selector); // Also scan the form for shadow elements - foundInputs = [...formElements, ...(0, _autofillUtils.findElementsInShadowTree)(this.form, selector)]; + const foundInputs = this.getFormElements(selector); if (foundInputs.length < MAX_INPUTS_PER_FORM) { foundInputs.forEach(input => this.addInput(input)); } else { @@ -10662,8 +10663,8 @@ class DefaultScanner { if (realTarget instanceof HTMLInputElement && !realTarget.hasAttribute(ATTR_INPUT_TYPE)) { const parentForm = this.getParentForm(realTarget); - // If the parent form is an input element, we don't want to scan it further - if (parentForm instanceof HTMLInputElement) return; + // If the parent form is an input element or the same as the target, we don't want to scan it further. + if (parentForm instanceof HTMLInputElement || parentForm.isEqualNode(realTarget)) return; const hasShadowTree = event.target?.shadowRoot != null; const form = new _Form.Form(parentForm, realTarget, this.device, this.matching, this.shouldAutoprompt, hasShadowTree); this.forms.set(parentForm, form); diff --git a/src/Form/Form.js b/src/Form/Form.js index 3c0b07f15..2709c76ef 100644 --- a/src/Form/Form.js +++ b/src/Form/Form.js @@ -393,15 +393,18 @@ class Form { * If .elements doesn't work, it falls back to querySelectorAll. * Doesn't look for shadow elements. * @param {string} selector - * @returns + * @returns {Element[]} */ getFormElements(selector) { // Some sites seem to be overriding `form.elements`, so we need to check if it's still iterable. + /** @type {Element[]|NodeListOf} element */ + let formElements = []; if (this.form instanceof HTMLFormElement && this.form.elements != null && Symbol.iterator in Object(this.form.elements)) { - return [...this.form.elements].filter((el) => el.matches(selector)); + formElements = [...this.form.elements].filter((el) => el.matches(selector)); } else { - return this.form.querySelectorAll(selector); + formElements = this.form.querySelectorAll(selector); } + return [...formElements, ...findElementsInShadowTree(this.form, selector)]; } categorizeInputs() { @@ -411,12 +414,9 @@ class Form { this.addInput(this.form); } else { /** @type {Element[] | NodeList} */ - let foundInputs = []; - - const formElements = this.getFormElements(selector); // Also scan the form for shadow elements - foundInputs = [...formElements, ...findElementsInShadowTree(this.form, selector)]; + const foundInputs = this.getFormElements(selector); if (foundInputs.length < MAX_INPUTS_PER_FORM) { foundInputs.forEach((input) => this.addInput(input)); diff --git a/src/Scanner.js b/src/Scanner.js index 99d6d9cd3..00ffe6762 100644 --- a/src/Scanner.js +++ b/src/Scanner.js @@ -439,8 +439,8 @@ class DefaultScanner { if (realTarget instanceof HTMLInputElement && !realTarget.hasAttribute(ATTR_INPUT_TYPE)) { const parentForm = this.getParentForm(realTarget); - // If the parent form is an input element, we don't want to scan it further - if (parentForm instanceof HTMLInputElement) return; + // If the parent form is an input element or the same as the target, we don't want to scan it further. + if (parentForm instanceof HTMLInputElement || parentForm.isEqualNode(realTarget)) return; const hasShadowTree = event.target?.shadowRoot != null; const form = new Form(parentForm, realTarget, this.device, this.matching, this.shouldAutoprompt, hasShadowTree); diff --git a/swift-package/Resources/assets/autofill-debug.js b/swift-package/Resources/assets/autofill-debug.js index ec650067f..7e2bc6091 100644 --- a/swift-package/Resources/assets/autofill-debug.js +++ b/swift-package/Resources/assets/autofill-debug.js @@ -10219,15 +10219,18 @@ class Form { * If .elements doesn't work, it falls back to querySelectorAll. * Doesn't look for shadow elements. * @param {string} selector - * @returns + * @returns {Element[]} */ getFormElements(selector) { // Some sites seem to be overriding `form.elements`, so we need to check if it's still iterable. + /** @type {Element[]|NodeListOf} element */ + let formElements = []; if (this.form instanceof HTMLFormElement && this.form.elements != null && Symbol.iterator in Object(this.form.elements)) { - return [...this.form.elements].filter(el => el.matches(selector)); + formElements = [...this.form.elements].filter(el => el.matches(selector)); } else { - return this.form.querySelectorAll(selector); + formElements = this.form.querySelectorAll(selector); } + return [...formElements, ...(0, _autofillUtils.findElementsInShadowTree)(this.form, selector)]; } categorizeInputs() { const selector = this.matching.cssSelector('formInputsSelector'); @@ -10236,11 +10239,9 @@ class Form { this.addInput(this.form); } else { /** @type {Element[] | NodeList} */ - let foundInputs = []; - const formElements = this.getFormElements(selector); // Also scan the form for shadow elements - foundInputs = [...formElements, ...(0, _autofillUtils.findElementsInShadowTree)(this.form, selector)]; + const foundInputs = this.getFormElements(selector); if (foundInputs.length < MAX_INPUTS_PER_FORM) { foundInputs.forEach(input => this.addInput(input)); } else { @@ -14828,8 +14829,8 @@ class DefaultScanner { if (realTarget instanceof HTMLInputElement && !realTarget.hasAttribute(ATTR_INPUT_TYPE)) { const parentForm = this.getParentForm(realTarget); - // If the parent form is an input element, we don't want to scan it further - if (parentForm instanceof HTMLInputElement) return; + // If the parent form is an input element or the same as the target, we don't want to scan it further. + if (parentForm instanceof HTMLInputElement || parentForm.isEqualNode(realTarget)) return; const hasShadowTree = event.target?.shadowRoot != null; const form = new _Form.Form(parentForm, realTarget, this.device, this.matching, this.shouldAutoprompt, hasShadowTree); this.forms.set(parentForm, form); diff --git a/swift-package/Resources/assets/autofill.js b/swift-package/Resources/assets/autofill.js index e59cd0080..a5a8edb31 100644 --- a/swift-package/Resources/assets/autofill.js +++ b/swift-package/Resources/assets/autofill.js @@ -6053,15 +6053,18 @@ class Form { * If .elements doesn't work, it falls back to querySelectorAll. * Doesn't look for shadow elements. * @param {string} selector - * @returns + * @returns {Element[]} */ getFormElements(selector) { // Some sites seem to be overriding `form.elements`, so we need to check if it's still iterable. + /** @type {Element[]|NodeListOf} element */ + let formElements = []; if (this.form instanceof HTMLFormElement && this.form.elements != null && Symbol.iterator in Object(this.form.elements)) { - return [...this.form.elements].filter(el => el.matches(selector)); + formElements = [...this.form.elements].filter(el => el.matches(selector)); } else { - return this.form.querySelectorAll(selector); + formElements = this.form.querySelectorAll(selector); } + return [...formElements, ...(0, _autofillUtils.findElementsInShadowTree)(this.form, selector)]; } categorizeInputs() { const selector = this.matching.cssSelector('formInputsSelector'); @@ -6070,11 +6073,9 @@ class Form { this.addInput(this.form); } else { /** @type {Element[] | NodeList} */ - let foundInputs = []; - const formElements = this.getFormElements(selector); // Also scan the form for shadow elements - foundInputs = [...formElements, ...(0, _autofillUtils.findElementsInShadowTree)(this.form, selector)]; + const foundInputs = this.getFormElements(selector); if (foundInputs.length < MAX_INPUTS_PER_FORM) { foundInputs.forEach(input => this.addInput(input)); } else { @@ -10662,8 +10663,8 @@ class DefaultScanner { if (realTarget instanceof HTMLInputElement && !realTarget.hasAttribute(ATTR_INPUT_TYPE)) { const parentForm = this.getParentForm(realTarget); - // If the parent form is an input element, we don't want to scan it further - if (parentForm instanceof HTMLInputElement) return; + // If the parent form is an input element or the same as the target, we don't want to scan it further. + if (parentForm instanceof HTMLInputElement || parentForm.isEqualNode(realTarget)) return; const hasShadowTree = event.target?.shadowRoot != null; const form = new _Form.Form(parentForm, realTarget, this.device, this.matching, this.shouldAutoprompt, hasShadowTree); this.forms.set(parentForm, form);