4

Browsers like Firefox or Chrome offer to remember the password when you login for the first time on a page; this functionality autofills the corresponding user/password combination in the login form the next time the user visits said page.

My question is, is there any way to become aware that the browser has autofilled these fields? the event change does not fire; in fact, according to monitorEvents nothing fires. I've resorted to use an interval that periodically checks whether the fields are empty or not, but is there a better way?

Mahn
  • 14,870
  • 12
  • 57
  • 77
  • `in fact, according to monitorEvents nothing fires.` - isn't that the answer to your question? – Ian Oct 05 '13 at 22:04
  • 1
    @Ian well yes, but I just wanted to make sure I'm not missing something trivial, since it seems something so basic it's hard to believe browser vendors would overlook it. – Mahn Oct 05 '13 at 22:05
  • @Ian actually I'm going to rephrase the question. – Mahn Oct 05 '13 at 22:09
  • I don't think there's a need for the browser to expose an event, because I'm guessing it happens on/before page load. So just check the values after the elements have rendered (safe to do on page load), and if they're empty (or if their `.value` is equal to their `.defaultValue`), nothing was saved/loaded. If they're filled, the browser did it. That's not all 100% reliable, but maybe I'm misunderstanding how the browser handles it – Ian Oct 05 '13 at 22:11
  • I think this could be helpful: http://stackoverflow.com/questions/32369/disable-browser-save-password-functionality – idmean Oct 06 '13 at 08:40
  • @Ian as far as I've observed this is correct *except* when the user has several user/password combinations saved. In this case, the fields don't get autofilled on load, but rather the password gets autofilled when the user chooses an username, which can happen at any point in time. – Mahn Oct 06 '13 at 12:55

1 Answers1

2

I am quite sure Chrome does fire the change event. I have experienced it recently (by accident). It is also already documented in Chromium Issue 135307.

Not sure about other browsers, but if you are write a periodic check will probably be the only solution. This code seems solid.

Ian Boyd
  • 220,884
  • 228
  • 805
  • 1,125
Pevara
  • 13,749
  • 1
  • 31
  • 44