javascriptauthenticationautofill

How can I detect a login form in a webpage using JavaScript?


I want to use JavaScript to detect if a webpage has a login form or not in order to autofill the user's credential. I'm thinking of checking if there is an input with id="username"/"id", however each website will have its own naming convention. What is the proper way to implement this?


Solution

  • I think the best way is to search for an input of type password. They are used only almost solely for logins. But you will also need to distinguish between login and signup forms. One way of doing it is counting the number of password inputs. Most signups have 2 password inputs to confirm. But this is less sure. You will probably need more filters. Maybe also try to find the words "signup" or "login" enclosed in the form tag, or immediately preceding it.

    There is no one sure way. You'll have to use your ingenuity.