Adjust improved field detection

This commit is contained in:
varjolintu 2023-08-23 10:34:15 +03:00
parent eb3657ead8
commit fe27cb87f2

View file

@ -202,9 +202,9 @@ kpxcObserverHelper.alreadyIdentified = function(target) {
}; };
kpxcObserverHelper.findInputsFromChildren = function(target) { kpxcObserverHelper.findInputsFromChildren = function(target) {
const children = []; const inputFields = [];
traverseChildren(target, children); traverseChildren(target, inputFields);
return children; return inputFields;
}; };
// Adds elements to a monitor array. Identifies the input fields. // Adds elements to a monitor array. Identifies the input fields.
@ -291,26 +291,26 @@ kpxcObserverHelper.ignoredNode = function(target) {
}; };
// Traverses all children, including Shadow DOM elements // Traverses all children, including Shadow DOM elements
const traverseChildren = function(target, children, depth = 1) { const traverseChildren = function(target, inputFields, depth = 1) {
depth++; depth++;
// Children can be scripts etc. so ignoredElement() is needed here // Children can be scripts etc. so ignoredNode() is needed here
if (depth >= MAX_CHILDREN || kpxcObserverHelper.ignoredElement(target)) { if (depth >= MAX_CHILDREN || kpxcObserverHelper.ignoredNode(target)) {
return; return;
} }
for (const child of target.childNodes) { for (const child of target.childNodes) {
if (child.type === 'hidden' || child.disabled) { if (child.type === 'hidden' || child.disabled || kpxcObserverHelper.ignoredNode(child)) {
continue; continue;
} }
if (child.nodeName === 'INPUT') { if (child.nodeName === 'INPUT') {
children.push(child); inputFields.push(child);
} }
traverseChildren(child, children, depth); traverseChildren(child, inputFields, depth);
if (child.shadowRoot) { if (child.shadowRoot) {
traverseChildren(child.shadowRoot, children, depth); traverseChildren(child.shadowRoot, inputFields, depth);
} }
} }
}; };