Is there a way to prevent the LastPass browser extension from filling out a HTML-based form with a input field with the name \"username\"?
This is an hidden field,
Two conditions have to be met:
autocomplete="off"
attributeSettings > Advanced > Allow pages to disable autofill
So this depends on both user and the developer.
For this latest October 2019 buggy release of Lastpass, this simple fix seems to be best.
Add
type="search"
to your input.
The lastpass routine checks the type
attribute to determine what to do with its autofill, and it does nothing on this html5 type
of "search." This fix is mildly hacky, but it's a one line change that can be easily removed when they fix their buggy script.
Note: After doing this, your input might appear to be styled differently by some browsers if they pick up on the type
attribute. If you observe this, you can prevent it from happening by setting the browser-specific CSS properties -webkit-appearance
and -moz-appearance
to 'none'
on your input.
This ES6 style code was helpful for me as it added data-lpignore to all my input controls:
const elements = document.getElementsByTagName("INPUT");
for (let element of elements) {
element.setAttribute("data-lpignore", "true");
}
To access a specific INPUT control, one could write something like this:
document.getElementById('userInput').setAttribute("data-lpignore", "true");
Or, you can do it by class name:
const elements = document.getElementsByClassName('no-last-pass');
for (let element of elements) {
element.setAttribute("data-lpignore", "true");
}
Tried the -search rename but for some reason that did not work. What worked for me is the following:
Tried and tested in latest versions of FF and Chrome.
I think lastpass honors the autocomplete="off"
attribute for inputs, but I'm not 100% sure.
EDIT As others have pointed out. this only works if the user has last pass configured to honor this.
Here's what worked for me to prevent lastpass from filling a razor @Html.EditorFor box in Chrome:
Click the active LastPass icon in your toolbar, then go to Account Options > Extension Preferences.
On this screen check "Don't overwrite fields that are already filled" (at the bottom)
Next, click "advanced" on the left.
On this screen check "Respect AutoComplete=off: allow websites to disable Autofill".
I did not need to do anything special in my ASP cshtml form but I did have a default value in the form for the @Html.EditorFor box.
I hope this helps and works for someone. I could not find any Razor-specific help on this problem on the web so I thought I'd add this since I figured it out with the help of above link and contributions.