Stop LastPass filling out a form

2019-01-21 12:38发布

问题:

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, so I don't want any software to use this field for their purposes:

<input type="text" name="username" id="checkusername" maxlength="9" value="1999" class="longinput" style="display:none">

The solution should not be like "rename the input field".

回答1:

Adding

data-lpignore="true"

to an input field disabled the grey LastPass [...] box for me.

Sourced from LastPass.com



回答2:

What worked for me is having word "-search-" in the id of the form, something like <form id="affiliate-search-form"> - and lastpass doesn't add its elements onto the form inputs. It works with something simpler like <form id="search"> but doesn't work with <form id="se1rch">



回答3:

Two conditions have to be met:

  1. The form (not the element) needs to have autocomplete="off" attribute
  2. Lastpass user needs to have this option enabled: Settings > Advanced > Allow pages to disable autofill

So this depends on both user and the developer.



回答4:

I know I'm late to the party here, but I found this when I was trying to stop lastpass from ruining my forms. @takeshin is correct in that autocomplete is not enough. I ended up doing the hack below just to hide the symbol. Not pretty, but I got rid of the icon.

If any lastpass developers are reading this, please give us an attribute to use, so we don't have to resort to stuff like this.

form[autocomplete="off"] input[type="text"] {
    background-position: 150% 50% !important;
}


回答5:

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.



回答6:

For me worked either type=search which is kinda equal to text or using role=note.

You can check the LastPass-JavaScript but it's huge, may be you can find some workaround there, from what I saw they only check 4 input types, so input type=search would be one workaround:

!c.form && ("text" == c.type || "password" == c.type || "url" == c.type || "email" == c.type) && lpIsVisible(c))

Also those are the role-keywords they seem to ignore:

var c = b.getAttribute("role");
switch (c) {
case "navigation":
case "banner":
case "contentinfo":
case "note":
case "search":
case "seealso":
case "columnheader":
case "presentation":
case "toolbar":
case "directory":`

I checked LastPass' onloadwff.js, prepare for 26.960 lines of code :)



回答7:

Add "search" to input id

<input type="text" name="user" id="user-search"/>


回答8:

Bit late to the party but I have just achieved this with modifying the form with:

<form autocomplete="off" name="lastpass-disable-search">

I guess this fools lastpass into thinking that it's a search form. This does not work for password fields however! Lastpass ignores the name field in this case.

The only way I've managed to do this is to add the following directly at the top of the form:

<form autocomplete="off">
    <div id="lp" ><input type="text" /><input type="password" /></div><script type="text/javascript">setTimeout(function(){document.getElementById('lp').style.display = 'none'},75);</script>
</form>

It causes a nasty flicker but does remove the autofill nonsense - though it does still show the "generate password" widget. LastPass waits until domready and then checks to see if there are any visible password fields, so it's not possible to hide or shrink the mock fields above.



回答9:

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");
}


回答10:

Tried the -search rename but for some reason that did not work. What worked for me is the following:

  1. mark form to autocomplete - autocomplete="off"
  2. change the form field input type to text
  3. add a new class to your css to mask the input, simulates a password field
  4. css bit: input.masker { -webkit-text-security: disc; }

Tried and tested in latest versions of FF and Chrome.



回答11:

None of the options here prevented LastPass from auto-filling my form fields unfortunately. I took a more sledge-hammer approach to the problem and asynchronously set the input name attributes via JavaScript instead. The following jQuery-dependent function (invoked from the form's onsubmit event handler) did the trick:

function setInputNames() {
    $('#myForm input').each(function(idx, el) {
        el = $(el);
        if (el.attr('tmp-name')) {
            el.attr('name', el.attr('tmp-name'));
        }
    });
}

$('#myForm').submit(setInputNames);

In the form, I simply used tmp-name attributes in place of the equivalent name attributes. Example:

<form id="myForm" method="post" action="/someUrl">
    <input name="username" type="text">
    <input tmp-name="password" type="password">
</form>