Skip to content

Commit

Permalink
More accuracy improvements (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
GioSensation authored May 4, 2022
1 parent 8cf1f27 commit dd9165a
Show file tree
Hide file tree
Showing 15 changed files with 1,025 additions and 31 deletions.
28 changes: 16 additions & 12 deletions dist/autofill.js
Original file line number Diff line number Diff line change
Expand Up @@ -4141,7 +4141,8 @@ class Form {
}

if (this.shouldOpenTooltip(e, input)) {
if ((0, _autofillUtils.isEventWithinDax)(e, input) || this.device.globalConfig.isMobileApp) {
if (this.device.globalConfig.isMobileApp && // Avoid the icon capturing clicks on small fields making it impossible to focus
input.offsetWidth > 50 && (0, _autofillUtils.isEventWithinDax)(e, input)) {
e.preventDefault();
e.stopImmediatePropagation();
}
Expand Down Expand Up @@ -6007,15 +6008,16 @@ const matchingConfiguration = {
ddgMatcher: {
matchers: {
email: {
match: '.mail',
match: '.mail\\b',
skip: 'phone',
forceUnknown: 'search|filter|subject'
},
password: {
match: 'password',
forceUnknown: 'captcha'
},
username: {
match: '(user|account|apple)((.)?(name|id|login).?)?$',
match: '(user|account|apple|login)((.)?(name|id|login).?)?$',
forceUnknown: 'search'
},
// CC
Expand Down Expand Up @@ -6043,16 +6045,18 @@ const matchingConfiguration = {
},
// Identities
firstName: {
match: '(first|given|fore).?name'
match: '(first|given|fore).?name',
skip: 'last'
},
middleName: {
match: '(middle|additional).?name'
},
lastName: {
match: '(last|family|sur)[^i]?name'
match: '(last|family|sur)[^i]?name',
skip: 'first'
},
fullName: {
match: '^(full.?|whole\\s)?name\\b',
match: '^(full.?|whole\\s|first.*last\\s|contact.?)?name\\b',
forceUnknown: 'company|org|item'
},
phone: {
Expand All @@ -6061,7 +6065,7 @@ const matchingConfiguration = {
},
addressStreet: {
match: 'address',
forceUnknown: '\\bip\\b|duck',
forceUnknown: '\\bip\\b|duck|web|url',
skip: 'address.*(2|two)|email|log.?in|sign.?in'
},
addressStreet2: {
Expand Down Expand Up @@ -6948,7 +6952,7 @@ class Matching {
/** @type {MatchableStrings[]} */


const stringsToMatch = ['nameAttr', 'labelText', 'placeholderAttr', 'id', 'relatedText'];
const stringsToMatch = ['placeholderAttr', 'nameAttr', 'labelText', 'id', 'relatedText'];

for (let stringName of stringsToMatch) {
let elementString = this.activeElementStrings[stringName];
Expand Down Expand Up @@ -7371,7 +7375,7 @@ function createMatching() {
"use strict";

const FORM_INPUTS_SELECTOR = "\ninput:not([type=submit]):not([type=button]):not([type=checkbox]):not([type=radio]):not([type=hidden]):not([type=file]),\nselect";
const SUBMIT_BUTTON_SELECTOR = "\ninput[type=submit],\ninput[type=button],\nbutton:not([role=switch]):not([role=link]),\n[class*=submit i][class*=button i],\n[role=button]";
const SUBMIT_BUTTON_SELECTOR = "\ninput[type=submit],\ninput[type=button],\nbutton:not([role=switch]):not([role=link]),\n[role=button]";
const email = "\ninput:not([type])[name*=mail i]:not([placeholder*=search i]):not([placeholder*=filter i]):not([placeholder*=subject i]),\ninput[type=\"\"][name*=mail i]:not([placeholder*=search i]):not([placeholder*=filter i]):not([placeholder*=subject i]),\ninput[type=text][name*=mail i]:not([placeholder*=search i]):not([placeholder*=filter i]):not([placeholder*=subject i]),\ninput:not([type])[placeholder*=mail i]:not([placeholder*=search i]):not([placeholder*=filter i]):not([placeholder*=subject i]),\ninput[type=text][placeholder*=mail i]:not([placeholder*=search i]):not([placeholder*=filter i]):not([placeholder*=subject i]),\ninput[type=\"\"][placeholder*=mail i]:not([placeholder*=search i]):not([placeholder*=filter i]):not([placeholder*=subject i]),\ninput:not([type])[placeholder*=mail i]:not([placeholder*=search i]):not([placeholder*=filter i]):not([placeholder*=subject i]),\ninput[type=email],\ninput[type=text][aria-label*=mail i]:not([aria-label*=search i]),\ninput:not([type])[aria-label*=mail i]:not([aria-label*=search i]),\ninput[type=text][placeholder*=mail i]:not([placeholder*=search i]):not([placeholder*=filter i]):not([placeholder*=subject i]),\ninput[name=username][type=email],\ninput[autocomplete=email]"; // We've seen non-standard types like 'user'. This selector should get them, too

const GENERIC_TEXT_FIELD = "\ninput:not([type=button]):not([type=checkbox]):not([type=color]):not([type=date]):not([type=datetime-local]):not([type=datetime]):not([type=file]):not([type=hidden]):not([type=month]):not([type=number]):not([type=radio]):not([type=range]):not([type=reset]):not([type=search]):not([type=submit]):not([type=time]):not([type=url]):not([type=week])";
Expand All @@ -7386,7 +7390,7 @@ const firstName = "\n[name*=fname i], [autocomplete*=given-name i],\n[name*=firs
const middleName = "\n[name*=mname i], [autocomplete*=additional-name i],\n[name*=middlename i], [autocomplete*=middlename i],\n[name*=middle-name i], [autocomplete*=middle-name i],\n[name*=middle_name i], [autocomplete*=middle_name i],\n[name*=additionalname i], [autocomplete*=additionalname i],\n[name*=additional-name i],\n[name*=additional_name i], [autocomplete*=additional_name i]";
const lastName = "\n[name=lname], [autocomplete*=family-name i],\n[name*=lastname i], [autocomplete*=lastname i],\n[name*=last-name i], [autocomplete*=last-name i],\n[name*=last_name i], [autocomplete*=last_name i],\n[name*=familyname i], [autocomplete*=familyname i],\n[name*=family-name i],\n[name*=family_name i], [autocomplete*=family_name i],\n[name*=surname i], [autocomplete*=surname i]";
const fullName = "\n[name=name], [autocomplete=name],\n[name*=fullname i], [autocomplete*=fullname i],\n[name*=full-name i], [autocomplete*=full-name i],\n[name*=full_name i], [autocomplete*=full_name i],\n[name*=your-name i], [autocomplete*=your-name i]";
const phone = "\n[name*=phone i], [name*=mobile i], [autocomplete=tel]";
const phone = "\n[name*=phone i], [name*=mobile i], [autocomplete=tel], [placeholder*=\"phone number\" i]";
const addressStreet1 = "\n[name=address], [autocomplete=street-address], [autocomplete=address-line1],\n[name=street],\n[name=ppw-line1], [name*=addressLine1 i]";
const addressStreet2 = "\n[name=address], [autocomplete=address-line2],\n[name=ppw-line2], [name*=addressLine2 i]";
const addressCity = "\n[name=city], [autocomplete=address-level2],\n[name=ppw-city], [name*=addressCity i]";
Expand Down Expand Up @@ -8880,7 +8884,7 @@ const setValueForSelect = (el, val) => {
} // TODO: try to match localised month names


if (value.includes(String(val))) {
if (value === String(val)) {
if (option.selected) return false;
option.selected = true;
fireEventsOnSelect(el);
Expand All @@ -8889,7 +8893,7 @@ const setValueForSelect = (el, val) => {
}

for (const option of el.options) {
if (option.innerText.includes(String(val))) {
if (option.innerText === String(val)) {
if (option.selected) return false;
option.selected = true;
fireEventsOnSelect(el);
Expand Down
7 changes: 6 additions & 1 deletion src/Form/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,12 @@ class Form {
}

if (this.shouldOpenTooltip(e, input)) {
if (isEventWithinDax(e, input) || this.device.globalConfig.isMobileApp) {
if (
this.device.globalConfig.isMobileApp &&
// Avoid the icon capturing clicks on small fields making it impossible to focus
input.offsetWidth > 50 &&
isEventWithinDax(e, input)
) {
e.preventDefault()
e.stopImmediatePropagation()
}
Expand Down
12 changes: 6 additions & 6 deletions src/Form/matching-configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,9 @@ const matchingConfiguration = {
/** @type {DDGMatcherConfiguration} */
ddgMatcher: {
matchers: {
email: {match: '.mail', forceUnknown: 'search|filter|subject'},
email: {match: '.mail\\b', skip: 'phone', forceUnknown: 'search|filter|subject'},
password: {match: 'password', forceUnknown: 'captcha'},
username: {match: '(user|account|apple)((.)?(name|id|login).?)?$', forceUnknown: 'search'},
username: {match: '(user|account|apple|login)((.)?(name|id|login).?)?$', forceUnknown: 'search'},

// CC
cardName: {match: '(card.*name|name.*card)|(card.*holder|holder.*card)|(card.*owner|owner.*card)'},
Expand All @@ -271,14 +271,14 @@ const matchingConfiguration = {
},

// Identities
firstName: {match: '(first|given|fore).?name'},
firstName: {match: '(first|given|fore).?name', skip: 'last'},
middleName: {match: '(middle|additional).?name'},
lastName: {match: '(last|family|sur)[^i]?name'},
fullName: {match: '^(full.?|whole\\s)?name\\b', forceUnknown: 'company|org|item'},
lastName: {match: '(last|family|sur)[^i]?name', skip: 'first'},
fullName: {match: '^(full.?|whole\\s|first.*last\\s|contact.?)?name\\b', forceUnknown: 'company|org|item'},
phone: {match: 'phone', skip: 'code|pass'},
addressStreet: {
match: 'address',
forceUnknown: '\\bip\\b|duck',
forceUnknown: '\\bip\\b|duck|web|url',
skip: 'address.*(2|two)|email|log.?in|sign.?in'
},
addressStreet2: {
Expand Down
2 changes: 1 addition & 1 deletion src/Form/matching.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ class Matching {
return { matched: false }
}
/** @type {MatchableStrings[]} */
const stringsToMatch = ['nameAttr', 'labelText', 'placeholderAttr', 'id', 'relatedText']
const stringsToMatch = ['placeholderAttr', 'nameAttr', 'labelText', 'id', 'relatedText']
for (let stringName of stringsToMatch) {
let elementString = this.activeElementStrings[stringName]
if (!elementString) continue
Expand Down
3 changes: 1 addition & 2 deletions src/Form/selectors-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const SUBMIT_BUTTON_SELECTOR = `
input[type=submit],
input[type=button],
button:not([role=switch]):not([role=link]),
[class*=submit i][class*=button i],
[role=button]`

const email = `
Expand Down Expand Up @@ -125,7 +124,7 @@ const fullName = `
[name*=your-name i], [autocomplete*=your-name i]`

const phone = `
[name*=phone i], [name*=mobile i], [autocomplete=tel]`
[name*=phone i], [name*=mobile i], [autocomplete=tel], [placeholder*="phone number" i]`

const addressStreet1 = `
[name=address], [autocomplete=street-address], [autocomplete=address-line1],
Expand Down
4 changes: 2 additions & 2 deletions src/Form/test-cases/coinmarketcap_login.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</div>
<div class="dgbbt4-3 kIcwIq">
<div class="label">Email Address</div><input type="email" placeholder="Enter your email address..."
class="snii6e-0 hZBOek" value="abc" data-manual-scorig="username">
class="snii6e-0 hZBOek" value="abc" data-manual-scoring="username">
</div>
<div class="dgbbt4-3 kIcwIq last">
<div class="label"><span>Password</span><span class="label-pwd">Forgot password?</span></div>
Expand Down Expand Up @@ -40,4 +40,4 @@
</div>
</div>
</div>
</div>
</div>
40 changes: 40 additions & 0 deletions src/Form/test-cases/gunderassociates_contacts.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!-- https://www.gunderassociates.com/contact-us/ -->
<form class="elementor-form" method="post" name="Contact Form">
<input type="hidden" name="post_id" value="92">
<input type="hidden" name="form_id" value="6018bb3">
<input type="hidden" name="referer_title" value="Contact Us">

<input type="hidden" name="queried_id" value="92">

<div class="elementor-form-fields-wrapper elementor-labels-above">
<div class="elementor-field-type-text elementor-field-group elementor-column elementor-field-group-name elementor-col-100 elementor-field-required">
<label for="form-field-name" class="elementor-field-label">
Name </label>
<input size="1" type="text" name="form_fields[name]" id="form-field-name" class="elementor-field elementor-size-sm elementor-field-textual" placeholder="First and Last Name" required="required" aria-required="true" data-manual-scoring="fullName">
</div>
<div class="elementor-field-type-tel elementor-field-group elementor-column elementor-field-group-email elementor-col-100">
<label for="form-field-email" class="elementor-field-label">
Phone Number </label>
<input size="1" type="tel" name="form_fields[email]" id="form-field-email" class="elementor-field elementor-size-sm elementor-field-textual" placeholder="Phone Number" pattern="[0-9()#&amp;+*-=.]+" title="Only numbers and phone characters (#, -, *, etc) are accepted." data-manual-scoring="phone">

</div>
<div class="elementor-field-type-email elementor-field-group elementor-column elementor-field-group-field_1305748 elementor-col-100 elementor-field-required">
<label for="form-field-field_1305748" class="elementor-field-label">
Email </label>
<input size="1" type="email" name="form_fields[field_1305748]" id="form-field-field_1305748" class="elementor-field elementor-size-sm elementor-field-textual" placeholder="Email" required="required" aria-required="true" data-manual-scoring="emailAddress">
</div>
<div class="elementor-field-type-textarea elementor-field-group elementor-column elementor-field-group-message elementor-col-100 elementor-field-required">
<label for="form-field-message" class="elementor-field-label">
Message </label>
<textarea class="elementor-field-textual elementor-field elementor-size-sm" name="form_fields[message]" id="form-field-message" rows="4" placeholder="Message" required="required" aria-required="true"></textarea> </div>
<div class="elementor-field-group elementor-column elementor-field-type-submit elementor-col-100 e-form__buttons">
<button type="submit" class="elementor-button elementor-size-sm" data-manual-submit>
<span>
<span class=" elementor-button-icon">
</span>
<span class="elementor-button-text">Send</span>
</span>
</button>
</div>
</div>
</form>
17 changes: 12 additions & 5 deletions src/Form/test-cases/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export default [
{ html: 'techradar_newsletter.html', title: 'AccessSubscription', expectedSubmitFalsePositives: 1 },
{ html: 'github_login.html' },
{ html: 'github_signup.html', expectedSubmitFalsePositives: 4 },
{ html: 'imdb_login.html', expectedSubmitFalsePositives: 1 },
{ html: 'imdb_login.html' },
{ html: 'imdb_signup.html' },
{ html: 'kleinanzeigen_login.html' },
{ html: 'kleinanzeigen_signup.html' },
Expand All @@ -140,7 +140,7 @@ export default [
{ html: 'cnbc_signup.html' },
{ html: 'cnbc_newsletter.html' },
{ html: 'researchgate_login.html' },
{ html: 'researchgate_signup.html', expectedSubmitFalsePositives: 1 },
{ html: 'researchgate_signup.html' },
{ html: 'wordreference_newsletter.html' },
{ html: 'rightmove_login.html' },
{ html: 'rightmove_signup.html', expectedSubmitFalseNegatives: 1 },
Expand All @@ -164,7 +164,7 @@ export default [
{ html: 'apartments_signup.html' },
{ html: 'opticsplanet_login.html' },
{ html: 'opticsplanet_signup.html' },
{ html: 'opticsplanet_checkout.html', expectedFailures: ['unknown'], expectedSubmitFalsePositives: 6, expectedSubmitFalseNegatives: 1 },
{ html: 'opticsplanet_checkout.html', expectedFailures: ['unknown'], expectedSubmitFalsePositives: 5, expectedSubmitFalseNegatives: 1 },
{ html: 'opticsplanet_newsletter.html' },
{ html: 'ifixit_login.html' },
{ html: 'ifixit_signup.html' },
Expand All @@ -186,7 +186,7 @@ export default [
{ html: 'usnews_contact.html' },
{ html: 'usnews_newsletter.html' },
{ html: 'babycenter_login.html' },
{ html: 'babycenter_signup.html', expectedSubmitFalsePositives: 1 },
{ html: 'babycenter_signup.html' },
{ html: 'yourtango_login.html' },
{ html: 'yourtango_signup.html' },
{ html: 'newgrounds_login.html' },
Expand Down Expand Up @@ -222,5 +222,12 @@ export default [
{ html: 'thermoworks_newsletter.html' },
{ html: 'wikihow_login.html' },
{ html: 'wikihow_signup.html', expectedFailures: ['fullName'] },
{ html: 'airbnb_login_signup.html' }
{ html: 'airbnb_login_signup.html' },
{ html: 'iqgunder_guest.html', expectedFailures: ['fullName', 'fullName', 'phone', 'fullName', 'fullName', 'phone', 'fullName', 'fullName', 'fullName', 'fullName', 'fullName', 'fullName'] },
{ html: 'iqgunder_guest_entry.html', title: 'Fund Formation Portal Login', expectedFailures: ['emailAddress'] },
{ html: 'iqgunder_login.html' },
{ html: 'iqgunder_signup.html' },
{ html: 'gunderassociates_contacts.html', expectedFailures: ['phone'] },
{ html: 'websitecarbon.html' },
{ html: 'schwab.html' }
]
Loading

0 comments on commit dd9165a

Please sign in to comment.