Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore small email inputs #261

Merged
merged 1 commit into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion dist/autofill-debug.js

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

27 changes: 26 additions & 1 deletion dist/autofill.js

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

4 changes: 4 additions & 0 deletions integration-test/pages/email-autofill.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@

<p id="demo"></p>

<div>
Small inputs should be ignored: <input id="email" type="email" style="width: 30px;">
</div>

<div class="dialog">
<form action="/signup">
<h2>Sign up for our newsletter</h2>
Expand Down
27 changes: 26 additions & 1 deletion src/Form/matching.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import { matchingConfiguration } from './matching-configuration.js'

const { TEXT_LENGTH_CUTOFF, ATTR_INPUT_TYPE } = constants

/** @type {{[K in keyof MatcherLists]?: { minWidth: number }} } */
const dimensionBounds = {
email: { minWidth: 40 }
}

/**
* An abstraction around the concept of classifying input fields.
*
Expand Down Expand Up @@ -178,6 +183,26 @@ class Matching {
return selectors.join(', ')
}

/**
* Returns true if the field is visible and large enough
* @param {keyof MatcherLists} matchedType
* @param {HTMLInputElement} input
* @returns {boolean}
*/
isInputLargeEnough (matchedType, input) {
const expectedDimensionBounds = dimensionBounds[matchedType]
if (!expectedDimensionBounds) return true

const width = input.offsetWidth
const height = input.offsetHeight

// Ignore hidden elements as we can't determine their dimensions
const isHidden = height === 0 && width === 0
if (isHidden) return true

return width >= expectedDimensionBounds.minWidth
}

/**
* Tries to infer the input type for an input
*
Expand Down Expand Up @@ -208,7 +233,7 @@ class Matching {
return 'credentials.password'
}

if (this.subtypeFromMatchers('email', input)) {
if (this.subtypeFromMatchers('email', input) && this.isInputLargeEnough('email', input)) {
if (opts.isLogin || opts.isHybrid) {
// Show identities when supported and there are no credentials
if (opts.supportsIdentitiesAutofill && !opts.hasCredentials) {
Expand Down
27 changes: 26 additions & 1 deletion swift-package/Resources/assets/autofill-debug.js

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

27 changes: 26 additions & 1 deletion swift-package/Resources/assets/autofill.js

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