Skip to content

Commit

Permalink
feat: evaluate checkboxes
Browse files Browse the repository at this point in the history
  • Loading branch information
dbajpeyi committed Jan 8, 2025
1 parent 396de3c commit f7a6e90
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 0 deletions.
19 changes: 19 additions & 0 deletions dist/autofill-debug.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions dist/autofill.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions src/Form/FormAnalyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ class FormAnalyzer {
shouldFlip = false;
}
this.updateSignal({ string, strength, signalType: `external link: ${string}`, shouldFlip });
} else if (el.matches(this.matching.cssSelector('enabledCheckboxSelector')) && this.isPersistentSigninText(string)) {
this.decreaseSignalBy(3, 'checkbox: persistent sign-in');
} else {
// any other case
const isH1Element = el.tagName === 'H1';
Expand Down Expand Up @@ -383,6 +385,15 @@ class FormAnalyzer {
this._isCCForm = Boolean(textMatches && deDupedMatches.size > 1);
return this._isCCForm;
}

/**
* Checks if the text is a persistent sign-in text, e.g "stay signed in" or "remember me"
* @param {string} text
* @returns {boolean}
*/
isPersistentSigninText(text) {
return /stay.?signed.?in|remember.?me/i.test(text);
}
}

export default FormAnalyzer;

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/Form/matching-config/selectors-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ button:not([role=switch]):not([role=link]),
a[href="#"][id*=button i],
a[href="#"][id*=btn i]`;

const enabledCheckboxSelector = 'input[type="checkbox"]:not([disabled])';

const safeUniversalSelector = '*:not(select):not(option):not(script):not(noscript):not(style):not(br)';

const emailAddress = [
Expand Down Expand Up @@ -279,6 +281,7 @@ const selectors = {
formInputsSelectorWithoutSelect,
formInputsSelector,
safeUniversalSelector,
enabledCheckboxSelector,

// Credentials
emailAddress,
Expand Down
7 changes: 7 additions & 0 deletions src/autofill-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,13 @@ const getTextShallow = (el) => {
if (el.type === 'image') {
return removeExcessWhitespace(el.alt || el.value || el.title || el.name);
}

// If it's checkbox, check for the first label to keep it simple.
// If there are multiple ones, we want to be on the safe side and ignore them,
// as the text can be noisy, resulting in false positives on the caller side.
if (el.type === 'checkbox' && el.labels?.length === 1) {
return removeExcessWhitespace(el.labels[0].textContent);
}
}

let text = '';
Expand Down
Loading

0 comments on commit f7a6e90

Please sign in to comment.