Skip to content

Commit f7a6e90

Browse files
committed
feat: evaluate checkboxes
1 parent 396de3c commit f7a6e90

File tree

8 files changed

+98
-0
lines changed

8 files changed

+98
-0
lines changed

dist/autofill-debug.js

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/autofill.js

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Form/FormAnalyzer.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,8 @@ class FormAnalyzer {
298298
shouldFlip = false;
299299
}
300300
this.updateSignal({ string, strength, signalType: `external link: ${string}`, shouldFlip });
301+
} else if (el.matches(this.matching.cssSelector('enabledCheckboxSelector')) && this.isPersistentSigninText(string)) {
302+
this.decreaseSignalBy(3, 'checkbox: persistent sign-in');
301303
} else {
302304
// any other case
303305
const isH1Element = el.tagName === 'H1';
@@ -383,6 +385,15 @@ class FormAnalyzer {
383385
this._isCCForm = Boolean(textMatches && deDupedMatches.size > 1);
384386
return this._isCCForm;
385387
}
388+
389+
/**
390+
* Checks if the text is a persistent sign-in text, e.g "stay signed in" or "remember me"
391+
* @param {string} text
392+
* @returns {boolean}
393+
*/
394+
isPersistentSigninText(text) {
395+
return /stay.?signed.?in|remember.?me/i.test(text);
396+
}
386397
}
387398

388399
export default FormAnalyzer;

src/Form/matching-config/__generated__/compiled-matching-config.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Form/matching-config/selectors-css.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ button:not([role=switch]):not([role=link]),
1515
a[href="#"][id*=button i],
1616
a[href="#"][id*=btn i]`;
1717

18+
const enabledCheckboxSelector = 'input[type="checkbox"]:not([disabled])';
19+
1820
const safeUniversalSelector = '*:not(select):not(option):not(script):not(noscript):not(style):not(br)';
1921

2022
const emailAddress = [
@@ -279,6 +281,7 @@ const selectors = {
279281
formInputsSelectorWithoutSelect,
280282
formInputsSelector,
281283
safeUniversalSelector,
284+
enabledCheckboxSelector,
282285

283286
// Credentials
284287
emailAddress,

src/autofill-utils.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,13 @@ const getTextShallow = (el) => {
367367
if (el.type === 'image') {
368368
return removeExcessWhitespace(el.alt || el.value || el.title || el.name);
369369
}
370+
371+
// If it's checkbox, check for the first label to keep it simple.
372+
// If there are multiple ones, we want to be on the safe side and ignore them,
373+
// as the text can be noisy, resulting in false positives on the caller side.
374+
if (el.type === 'checkbox' && el.labels?.length === 1) {
375+
return removeExcessWhitespace(el.labels[0].textContent);
376+
}
370377
}
371378

372379
let text = '';

0 commit comments

Comments
 (0)