23

I've stumbled across this issue a couple of times in the last while, where Chrome ignores autocomplete="false" and autocomplete="off". It will now even ignore autocomplete="whatever" or anything you do to trick it, if someone has submitted a form with that random "hack" in it before.

In trying to solve this issue, I came across this StackOverflow question, which doesn't solve the problem if you've submitted a form containing this field before.

EDIT: This is NOT for password fields.

Rob
  • 14,746
  • 28
  • 47
  • 65
3Dom
  • 795
  • 3
  • 10
  • 22
  • 3
    @JosephSible-ReinstateMonica This isn't breaking password managers, it's not for a password field at all. My web-app cannot have this field autocompleted. Not an option. Chrome needs to start respecting the directives in the HTML spec. This is NOT for password fields. Besides, password fields have the type="password" set on them, which would make this hack ineffective. – 3Dom Mar 15 '20 at 04:42
  • It is important to know that if you turn off autocomplete, you are breaking the rule 1.3.5: Identify Input Purpose in WCAG 2.1. If you are making a website that should follow WCAG, you should use autocomplete with autofill. https://www.w3.org/WAI/WCAG21/Understanding/identify-input-purpose.html – Stuart Aug 25 '20 at 10:17
  • 3
    @Stuart it is not for a browser to dictate how the designer uses a field. If the option to turn it off is in the toolset, it should work, and the browser should obey the directive. It shouldn't then create its own rules as some sort of omnipotent dictator. – 3Dom Aug 26 '20 at 00:04
  • That is not what I am saying. It is for the web designer to comply with the design principals of the web. And it should be that the designer helps, not hinder the user of their pages. – Stuart Aug 27 '20 at 06:18
  • It seems that the most recent answer for this problem is there : https://stackoverflow.com/questions/15738259/disabling-chrome-autofill#answer-30976223 – Foxlab Oct 09 '20 at 13:11
  • 1
    @Stuart "you are breaking the rule 1.3.5: Identify Input Purpose in WCAG 2.1".That's what the HTML label is for, is it not? Autocomplete is designed to help browsers provide automation in forms, not identify the field to the user (see https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete). Specifically note: "lets web developers specify what **if any** permission the user agent has to provide automated assistance in filling out form field values" – Francois Carstens Jan 20 '21 at 21:11
  • @FrancoisCarstens Well yes and no. The value of autocomplete="off" just means that I am not going to tell you what this field is for, not not to try and fill it. So if you are an evil web developer you set it to off, and frustrate users of your site, and receive more inaccurate data entries. The point is that all browsers and password managers will still fill in fields with autocomplete="off", so it is better to set this to the correct value of the data you are expecting. – Stuart Jan 22 '21 at 15:30
  • Well, I have a name text field and using Ajax, I provide the autocomplete (about 20,000 options) and on top of this, chrome messing up with unrelated data? WCAG will tell us what is good or bad? – fcm Jun 02 '21 at 20:53
  • Try https://github.com/terrylinooo/disableautofill.js – Terry Lin Nov 21 '22 at 02:15

17 Answers17

25

I had this issue with a field that has "number" in the name and this triggering the CreditCard Autocomplete Dialog. This solution helped me get rid of it.

Even though this is not the intended use of the option, I think this is unlikely to break and works without JavaScript Hacks. A one time code won't trigger an autocomplete so I treat the fields that are not supposed to autocomplete as one time codes.

<input type="text" name="number" autocomplete="one-time-code" />

This did the trick for me. I tested it in Chrome 87.0.4280.141 and it works fine.

risutoru
  • 455
  • 5
  • 13
  • For me, simply including the name attribute works to prevent autocomplete suggestions from showing – Kai Durai Jan 19 '21 at 14:55
  • @KaiDurai you go into that ? Since in my case I couldn't remove the autocomplete by adding or removing the name attribute. If your name attribute matches one of their regex or you have a label with it, you should get the autocomplete. No avoiding that at least that's what I could confirm and what research showed as well. – risutoru Jan 21 '21 at 08:13
  • The trick with does the job, thanks! – Dariusz Legizynski Jun 23 '21 at 06:37
  • razor pages adds a name to everything and that hasn't aleviated it. – J_sdev Jun 23 '21 at 20:09
  • as per your answer autocomplete="one-time-code" worked for all my fields I wanted to disable including password - thanks!! – DCX Feb 08 '23 at 14:30
  • Doesn't work for me, autocomplete popup still comes up,. – Keremcan Buyuktaskin Jun 12 '23 at 07:54
  • Doesn't work for me either, but it stopped autocomplete on the username field above :D – Richard Toth Jun 14 '23 at 07:43
9

autocomplete="new-password" and set placeholder attribute with some text works for me.

<input name="name1" placeholder="Nº" type="text" autocomplete="new-password" />
Pipebugs
  • 99
  • 1
  • 3
  • This one did work for me, where as most of the rest did not. (As of 1/6/2020) - Is there any indication or documentation about why "new-password" actually manages to prevent the autocomplete, while no other attribute/value combo seems to work. Also I didn't seem to need the placeholder value to make it work. – bobbysmith007 Jan 08 '21 at 18:56
  • Thank you. Worked like a charm. Let's hope google doesn't "fix" this soon – Oleksandr Fomin Oct 21 '21 at 20:10
7

Everytime I found a solution Chrome throws a spanner in the works again.

No longer working

  • autocomplete="new-*"
  • add an offscreen positioned bogus input element style="position: fixed;top:-100px;left:-100px;" as first <form> element
  • set <form autocomplete="off">
  • use <textarea> and style it as a field

Working solution (15 jul 2021)

Append a dummy <input> without a name attribute and make the original <input> type="hidden"

HTML

<input type="hidden" name="myfield" class="no-autofill"> <input>

Note that any events, (click, blur, focus) that show your custom autofill should be added to the visible <input> element.

Then add a change event to sync the value to the hidden input.

const fields = document.querySelectorAll('input.no-autofill');
for (const field of fields) {
  const dummy = field.nextElementSibling;
  dummy.addEventListener('change',e => {
    field.value = e.target.value;
  });
}

Ow, before implementing. Make sure you visit the Chromium bug tracker and tell the Chrome Developers why following the standard is important. So one day we might be able to just use:

<input name="myfield" autocomplete="off">
dehart
  • 1,554
  • 15
  • 18
3

its work in my local machine try it...

<input type="email" class="form-control" id="email" name="email" placeholder="Enter Email"  readonly onfocus="this.removeAttribute('readonly');" style="background-color: white;">
Mohammad Malek
  • 624
  • 1
  • 7
  • 17
2

It's November 2021, and none of the non-javascript solutions mentioned worked for my address-related field. What did work was actually changing the text in the label.

The Autocomplete dialog in Chrome was shown if:

  • The word "Address" is in the label at the start or end; and
  • There are at least two other address fields (seemingly anywhere in the page)

EDIT: If you put a zero-width joiner character entity in the middle of the word 'Address' in the label, the autocomplete dialog is suppressed!

i.e. set the label to Addres&zwj;s

html, body {
  font-family: 'Helvetica', Sans-Serif;
  font-weight: 200;
  line-height: 1.5em;
  padding: 1em;
}
<div class="addressDiv">
  <div>
    <label>Focus on this field...Address</label>
    <div>
      <input autocomplete="off" type="text" aria-autocomplete="none" autocapitalize="none" />
    </div>
  </div>
  <div>
    <label>State</label>
    <div>
      <input autocomplete="address-level1" type="text" value="">
    </div>
  </div>
  <div>
    <label>City</label>
    <div>
      <input autocomplete="address-level2" type="text" value="">
    </div>
  </div>
</div>
<p>
See <a href="https://jsfiddle.net/f490h2s6/">this JSFiddle</a>
</p>
cobberboy
  • 5,598
  • 2
  • 25
  • 22
1

Read the note at the bottom before using this method

After struggling for a long time, I made it work reliably this way:

It is important that your input type is 'text'!!

define a css class

input.hidden-password {
  -webkit-text-security: disc;
}

Then in your form, set autocomplete off, input types = 'text' and add the class to the input.

<form autocomplete="off">
    <input
      type = "text" // <----This is important
      class = "hidden-password"
    />
</form>

C'mon Google, let us take control over our inputs! My client requires passwords to be changed very often and auto fill IS A BIG NO NO!


IMPORTANT NOTE Do not use this for login or any other place where security is required. I used this for a form within my app where the user was already authenticated and security was not required.


Thales Kenne
  • 2,705
  • 1
  • 12
  • 26
1

For Me, the problem only occurs, if I have multiple fields with the same value for autocomplete. If I set the value to a random number (Math.random()), no autocomplete is happening. I think it would also be possible to use an otherwise unique string.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Stephan Hoyer
  • 4,792
  • 2
  • 29
  • 26
  • This worked for me. In the input field I set the name="{Math.random()}-false" and that disabled autocomplete in Chrome. – B-Rad Sep 30 '21 at 22:34
1

To prevent 'manage addresses' level of of chrome popup: autocomplete='chrome-off'

To prevent autosuggest popup, if you can swing it: EXCLUDE name and id attributes.

Sam S
  • 188
  • 1
  • 9
1

Dirty answer , edit "selectorForYourInputs" and works just fine, cross browser tested, max overhead 50ms, user never notice any performance lag:

counter = 0;
emptySearchboxInterval = setInterval(() => {
  $(selectorForYourInputs).val("");
  counter++;
  counter == 100 ? clearInterval(emptySearchboxInterval) : null;
}, 20);
nikhil swami
  • 2,360
  • 5
  • 15
0

here is JS solution that works at this point in time for me:

<input name="name" type="text"
        onfocus="this.__name = this.getAttribute('name'); this.removeAttribute('name')"
        onblur="this.setAttribute('name',this.__name)"
        >

The above js code stores input name to this.__name and removes the name onfocus later onblur name is restored so forms can work as expected, but chrome does not autofill.

Davor Hrg
  • 187
  • 1
  • 11
  • I already answered my own question and it does a better job of explaining it than you've done, even though your hack is good. – 3Dom Aug 23 '20 at 13:37
  • Actually chrome was ignoring even autocomplete="whatever" at the time I wrote the mentioned JS hack :) ... so if somene else is as unlucky as I am, this JS hack could help. – Davor Hrg Aug 24 '20 at 14:23
0

Try to make your input readonly, enable it after focus

<input readonly="readonly" onfocus="this.removeAttribute('readonly');" type="text" value="test">
Josh
  • 65
  • 6
  • I don't like this solution at all. It doesn't seem foolproof or futureproof enough. My own answer is more solid. – 3Dom Aug 23 '20 at 13:37
0

No known attribute value is working in form tag. I have tried them all: do-not-show-ac, chrome-off, new-password, off...

The only way i found is by adding autocomplete='new-password' to every input component. To do it globaly, i am using this jquery:

    <script>
        $('input').attr('autocomplete', 'new-password');
    </script>
tak3shi
  • 2,305
  • 1
  • 20
  • 33
0

The best way is to use JavaScript to skip browser's behavior, disableautofill.js does this.

You can try https://github.com/terrylinooo/disableautofill.js

<script src="https://cdn.jsdelivr.net/npm/disableautofill@2.0.0/dist/disableautofill.min.js"></script>

Usage:

 var daf = new disableautofill({
    'form': '#testForm', // Form id
    'fields': [
        '.test-pass',  // password
        '.test-pass2'  // confirm password
    ],
    'debug': true,
    'callback': function() {
        return checkForm(); // Form validator
    }
});

daf.init();
Dharman
  • 30,962
  • 25
  • 85
  • 135
Terry Lin
  • 2,529
  • 22
  • 21
0

How about just never submit the form? Nothing to remember!
Your app probably doesn't work without javascript anyway, right?

In fact, don't use a form at all, just collect the input values, serialize and do an ajax call.

$('#mybutton').on('click', function (e) {
    $.ajax({
        type: "POST",
        url: 'mybackend',
        data: $('#formdiv input').serialize(),
        success: function (data) ...

Mind you, this is not a well tested idea, just something I have observed when I wanted autofill, and which I have not seen suggested in any of the many threads dealing with this issue.

Alias_Knagg
  • 886
  • 1
  • 7
  • 21
0

I just resolved a related issue - it was forcing Chrome Autofill on an address field (Google Places Autocomplete, specifically) and no other solutions were working.

Eventually, we changed the nearest label to it from saying "Business Address" to being blank and set its text via CSS

#gmapsSearchLabel:after {
    content: "Business Address";
}

And without a nearby label "saying" address, it stopped forcing Autofill.

0

A solution that works for me is to place a zero-width-white-space character into the placeholder text, so for example:

placeholder="Enter your address" becomes

placeholder="Enter your a[ZWSP]ddress"

Chrome is then unable to find "address" and skips autocomplete suggestions.

You can copy the character ( don't use the html entity etc. ) over at CSS Tricks. Here is the word "address" with the ZWSP character after the letter "a":

a​ddress

enter image description here

dougwig
  • 526
  • 6
  • 8
0

Not work:

auto-complete="off"

autocomplete="new-password"

WORKED

<input type="text" readonly="readonly">

the key is readonly, and when it's ready for input, change the readonly attr value to false, or remove the attr.