When does form autocomplete happen?
Today for fixing a bug in Bugzilla I needed an event to fire only after the browser had automatically autocompleted the login form (what Firefox, Chrome, and Safari do when you have saved exactly one set of login credentials for a site). Most people would think that window.onload would work, and it does, in one browser--Chrome. Other people might try to use YUI's onDOMReady event, which fires when all the content is available in the DOM. That works in exactly one engine--Gecko.
The problem is that autocomplete happens at different times in different browsers, and you can't even rely on knowing what engine the browser is using--in WebKit-based browsers, it happens at different times depending on what browser is being used. Here's when autocomplete happens in different browsers:
- Gecko: Before onDOMReady, but after window.onload (so use onDOMReady).
- Chrome: After onDOMReady, but before window.onload (so use window.onload).
- Safari: After both onDOMReady and window.onload (so do a 200 millisecond window.setTimeout on window.onload).
- Opera: Never autocompletes forms without user interaction.
- IE: Never autocompletes forms without user interaction.
So the only reliable solution is to fallback to the Safari solution, which is to do something 200 milliseconds after window.onload. I tried 100ms, and I was getting into race conditions where sometimes my event would fire before autocomplete, sometimes it would fire after. I upped it to 200ms as a safe amount.
This is a little annoying if you want something to happen instantly after the form is autocompleted, so what I actually did for Bugzilla was I fired the event after onDOMReady for Gecko, and used the Safari solution for all other browsers.
Anyhow, it would be nice if this was all standardized some day.