Why Firefox autocomplete even with different input name?

后端 未结 4 1049
鱼传尺愫
鱼传尺愫 2021-02-12 20:15

Or How does Firefox determine where the password/username goes?

If I change name, id, title, class of an input element Firefox keeps filling it with password or email.

相关标签:
4条回答
  • 2021-02-12 20:47

    If I understand Firefox's source code correctly, the browser first looks for password fields in forms. If form contains more than 3 password fields, the autofill function ignores that form.

    After 1 to 3 password fields are found, the browser looks for login field. The browser does a backward search starting from first password field and assumes that the login field is the first found field of the type text or email or url or tel or number.

    Next step depends if we check the forms on page load or when submitting the form. If we check during page load and there is a login field and exactly ONE password field, the case is simple and the browser can fill out the form.

    Other cases (form submit or more than 1 password field) do some “smart” logic to determine which password field contains new password and which one the old password, probably to update stored passwords). If you're interested in details, download the source code and open toolkit/components/passwordmgr/nsLoginManager.js file. Functions to check are _fillForm, _getFormFields and _getPasswordFields.

    Just to summarize, Firefox doesn't need any ID, name or class attributes to guess which field is login or password. It just relies on types and the order of form fields.

    0 讨论(0)
  • 2021-02-12 20:52

    I tried a simple solution that is working so far. Create 2 hidden fields and the browser will autofill those.

    <input type="text" style="display: none">
    <input type="password" style="display: none">
    
    0 讨论(0)
  • 2021-02-12 20:56

    Looks like using a disabled input text between login and password inputs does the trick well :

    <input type="text" disabled="disabled" style="display:none">
    
    0 讨论(0)
  • 2021-02-12 21:09

    Are those the only two elements on the form? Firefox is likely storing the structure of the form (two input boxes, one flagged as normal, one flagged as password) and filling in saved information without respect to the ID of the input elements.

    Try this: add an extra input element to the form and see what happens. Either Firefox will not fill in anything, or you'll find your name in the first field and the password field filled in, while the second input element is blank.

    0 讨论(0)
提交回复
热议问题