My Firefox extension dynamically adds a username/password fields into every page. The problem 开发者_运维知识库is it does not remember what I enter as it normally do. Why this is happening?
Looking at nsLoginManager.js, forms are normally filled when the DOMContentLoaded
event fires (see _fillDocument()
call). From what I understand, you insert your elements after that event is already processed so that their values are no longer restored. You could call nsILoginManager.fillForm() explicitly however to restore field values after you changed the form:
Components.classes["@mozilla.org/login-manager;1"]
.getService(Components.interfaces.nsILoginManager)
.fillForm(form);
This should be sufficient, from the code it seems that having an id
attribute isn't necessary.
精彩评论