fix code auto-pasting by using better heuristics to find the input box #1423
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Instead of checking for specific keywords in the
name
orid
attributes of HTML input elements, we only need to find the first visible input element with correcttype
attributes and with no value or OTP-code-like values.I think it's really unstable to check for the appearance of an arbitrary list of keywords in the
name
orid
attributes, since website maintainers could use anything and it's never going to be exhaustive to match them all. Not to mention the current implementation could really match any hidden inputs that has these keywords in theirname
orid
. What I think a better way is to find the first visible input element on the page that also has the correcttype
attribute, because it's usually the case that the website will present a single page which includes a single visible input element to the user when asking for their OTP codes.Also, the new implementation always checks for the active element first and if it's a valid input element it will be used directly. I think this was the intention of the original implementation but I've encountered websites (e.g. Steam) that had hidden input elements that will be matched in the first stage and the function will simply return early.
I also use a single CSS selector to get all input elements with valid
type
attributes, instead of using a loop and an intermediate array to populate them.I've tested the new implementation on Steam (which the old implementation doesn't work) and other websites and can confirm that it's working fine. However, please do keep in mind that this is a completely different heuristic than the original one so it might break on certain websites, but I think we can improve this on future user reports.