The report goes something like this: "I open the login page, my email and password are already there, and the Sign in button is greyed out." You open the page. You type your test credentials. The button lights up. Closed, cannot reproduce.
The reporter was right, and so was your test. They had a saved password. You did not.
What Chrome does with a saved password on page load
When Chrome's password manager fills a login form as the page loads, it does not put the values into the fields. Chromium's own source is explicit about it, in password_autofill_agent.h:
On page load, PWM preliminarily autofills usernames and passwords in a way that keeps them inaccessible to JavaScript using SetSuggestedValue() and WebAutofillState::kAutofilled.
And the class that enforces it, PasswordValueGatekeeper, exists to ensure "that the autofilled values are not accessible to JavaScript code until the user interacts with the page". The comment gives the reasons as privacy and attack surface, and links the two Chromium bugs behind it.
So for that window, the user sees both fields filled and your code reads this:
emailInput.value // ""
passwordInput.value // ""
Both of them, not just the password. The gatekeeper registers "every autofilled username and password field".
What a page built on the obvious pattern does with that
Any code that reads the fields once and decides something gets the wrong answer:
- A Sign in button that starts disabled and is enabled by checking the values on load.
- A "Continue" step that validates on load and shows "Password is required" under a field that visibly contains one.
- A framework store initialised from the DOM, which now holds two empty strings and will not look again.
None of this happens in a clean test profile, because there is nothing saved to fill. It does not happen in Playwright or Cypress either, because the browsers they drive start with no saved passwords. It happens to returning users with saved passwords, which is to say the people most likely to be logging in at all.
When the values arrive, and what fires
The first time the user interacts with the page, the gatekeeper calls ShowValue on each field it held back, and that calls SetAutofillValue. In Blink's web_form_control_element.cc that function does more than set a value. For a field without focus it dispatches a focus event, then a synthetic keydown ("in case the website checks via JS that a keyboard interaction took place", says the comment), then sets the value, which sends input and change, then keyup, then blur.
That sequence is the whole fix, if your code is listening for it. A button whose state is recomputed on every input event recovers the moment the user clicks anywhere. One whose state was computed once on load does not, and since a disabled button does not dispatch click to your handler, the user can press it all day.
The synthetic focus and blur are worth knowing about as well. Validation that marks a field as touched on blur will consider both fields touched before the user has looked at them.
Telling "empty" from "filled, not yet released"
The field is in an autofilled state before its value is exposed, and CSS can see that state. In Blink, :autofill (and the older :-webkit-autofill) match when the field IsAutofilled(), which is exactly the state the preliminary fill sets. So:
function looksEmptyButIsnt(input) {
try {
return input.value === '' && input.matches(':autofill')
} catch {
return input.value === '' && input.matches(':-webkit-autofill')
}
}
Use it to avoid showing an error, not to read the password. The value stays out of reach until the user acts, by design, and nothing on the page should try to get round that.
The simpler fix is not to gate the button at all. Leave Sign in enabled and validate on submit. By the time anybody submits, they have clicked or pressed a key, the gatekeeper has released the values, and your validation sees what the user sees.
The general version
This is the shape of a lot of "cannot reproduce" closures: the state that triggers the bug is something the user has and the developer's test setup is built not to have. Saved passwords, an installed extension, a cookie from last month. If a report says the form was already filled in, believe that sentence before anything else in it.
Behaviour described here is Chrome's, from Chromium's source. I have not checked what other browsers do in the same window, so test those separately rather than assuming.
Top comments (0)