Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to trigger saved password autofill in browsers?

I have a web application written in pure JavaScript (no pre-generated HTML except for the document which loads all the JS files).

This app contains a login form which is created dynamically when the document.ready event event is triggered. I trick the browser into displaying the "Remember password?" dialog by posting the login form into a hidden iframe before logging in using ajax (in Firefox the password appears on the saved password list, so this part obviously works) but saved passwords never get filled in after the login screen is loaded again at a later time. The same thing happens in Firefox and Safari.

Is there something I can do or some function I can call to trigger autofill?

UPDATE: autofill works in Safari on initial page load, but not when user logs out and the login form is recreated without a page reload. In Firefox it never works.

like image 291
Aleksander Kmetec Avatar asked Apr 12 '10 09:04

Aleksander Kmetec


People also ask

How do you trigger Autofill?

In order to trigger autocomplete, make sure you correctly name the name and autocomplete attributes in your <input> tags. This will automatically allow for autocomplete on forms.

Why are my saved passwords not Autofilling?

Autofill issues related to passwords can also occur if you've prevented Chrome from saving login credentials for certain sites. Scroll down the list of passwords to the Never Saved section—you can then remove the sites you want Chrome to start saving (and auto-filling) again.


2 Answers

In addition to wrap the form elements in a form element, make sure all the input (and maybe even the form) has unique name and id attributes that doesn't change. The name should probably be something descriptive like password for the password etc., not really sure to which degree browsers use this info, but "autosuggest"/"magic wand" features may work better if you use a standard name.

And of course you should make sure you're not setting any autosuggest/autofill attributes to false (the js framework might do so for some reason, if you're using any).

A third possibility is that some browsers maybe does autofill before your script loads and writes the form to the page, try making a static html version of the form and see if that works.

The easiest solution (if static forms work) is to force a page reload on logout (you probably do want to discard the "state" of the running javascript after log-out anyway, so refreshing is really a Good Thing)

like image 155
Stein G. Strindhaug Avatar answered Nov 15 '22 17:11

Stein G. Strindhaug


Some browsers require "form" tag to enable local username & password storage. Had the same problem in AJAX application, and in my case I just added

<form>...</form>

tags.

like image 29
Andrew Bashtannik Avatar answered Nov 15 '22 17:11

Andrew Bashtannik