Most attempts to fix this problem involve hacking around browser heuristics for logins, which is error-prone and easily becomes outdated. So, we should see what browsers themselves recommend for working with their authentication features.
Sadly there’s no cross-browser standard yet (the upcoming isLoggedIn
API looks like it’ll be that), but in the meantime we have some advice from the Chromium Wiki’s Create Amazing Password Forms:
Make sure form submission is clear
Password managers need some indication that a form has been submitted.
Try to make sure your web page does one of the following on form
submission:
- Performs a navigation to another page.
- Emulates a navigation with History.pushState or History.replaceState, and removes the password form completely.
In addition, if you perform an asynchronous request with
XMLHttpRequest or fetch, make sure that the success status is
correctly set in the response headers.
Follow existing conventions
Being different just for the sake of it is not worth it. This will lead to a poor user experience all round. This means, for example, not navigating to a separate web page if a login failed: this is unexpected, and disorienting to both the user and the password manager.
From this, we can infer the following signals to at least one browser that a login failed:
The HTTP response’s status code is an error.
The form submission does not navigate to another page (login pages may reload if you failed to log in successfully, but crucially they stay at the same URL).
The form does not submit at all when the user tries — either because of HTML form validation blocking the submission, or JS checking if the server accepted the login and calling .preventDefault
on the form submission event. (The former is unsuitable for wrong credentials; only basic checks such as required
and minlength
.)
Sadly, I can confirm that some of these techniques don’t work cross-browser: for example, Firefox optimistically shows its Save Credentials menu before the HTTP response to the form submission even arrives. Mozilla has a bug open about this exact problem, but it appears doing the right thing to keep compatibility with existing sites is just as tricky for them.
More distressingly, from a duplicate of that bug:
Matthew N. [:MattN] • 2 years ago
We should double-check how other browsers handle this nowadays. I think others started copying us on this now.