简体   繁体   English

Chrome 自动填充/自动完成没有密码值

[英]Chrome Autofill/Autocomplete no value for password

When you have saved username and password for some site Chrome will autofill that username and password, but if you try to get the value for the password input field it is empty String even though there is value there ******.当您为某个站点保存了用户名和密码时,Chrome 会自动填充该用户名和密码,但是如果您尝试获取密码输入字段的值,它是空字符串,即使那里有值 ******。

If you click somewhere on the page no mater where the value of the input type="password" will be filled.如果您单击页面上的某个位置,则无论input type="password"的值将填充在哪里。

This is Fiddle user/pass of the structure of the html and the console.log command.这是 html 和console.log命令的结构的 Fiddle user/pass It cannot be seen here but it can be reproduced on every page that has login form and the username and password are autofilled on the load of the page.它在这里看不到,但可以在每个具有登录表单的页面上复制,并且用户名和密码会在页面加载时自动填充。 If you inspect the value of the field before clicking anywhere else on the site it will be empty String.如果您在单击网站上的其他任何地方之前检查该字段的值,它将是空字符串。

This is not the case in Firefox or Inte.net Explorer it will fill the value of the input element with the password.在 Firefox 或 Inte.net Explorer 中不是这种情况,它将用密码填充input元素的值。

I am using Windows 7 Ultimate 64-bit OS and Google Chrome version is 48.0.2564.97 m我使用的是 Windows 7 Ultimate 64 位操作系统,Google Chrome 版本是 48.0.2564.97 m

Is this normal behavior, bug or?这是正常行为,错误还是?

UPDATE:更新:

If you click on F5 to reload the page and inspect the password field the value for password will be there.如果您单击 F5 重新加载页面并检查密码字段,密码值将在那里。 If you click the reload button in Chrome in top left corner the value for the password field will be empty string.如果您单击左上角 Chrome 中的重新加载按钮,密码字段的值将为空字符串。

This seems to be a bug in Chrome.这似乎是 Chrome 中的一个错误。 When Chrome auto-fills a password on an initial page load (but not a refresh), the value appears in the form field on-screen, but querying passwordField.value in Javascript returns an empty string.当 Chrome 在初始页面加载(但不是刷新)时自动填充密码时,该值会出现在屏幕上的表单字段中,但在 Javascript 中查询passwordField.value返回一个空字符串。 If you depend on seeing that value in Javascript, this prevents you from doing so.如果您依赖于在 Javascript 中看到该值,这将阻止您这样做。 Once the user does any other action on the page, such as clicking anywhere on the page, the value suddenly becomes visible to Javascript.一旦用户在页面上执行任何其他操作,例如单击页面上的任意位置,该值就会突然对 Javascript 可见。

I'm not actually 100% sure if this is a bug, or if there is a security reason for doing this such as preventing a hidden frame from stealing your password by tricking the browser into filling it in.我实际上并不能 100% 确定这是否是一个错误,或者是否有这样做的安全原因,例如通过欺骗浏览器填写密码来防止隐藏框架窃取您的密码。

A workaround that we have used is to detect the background color change that Chrome makes to fields that it has auto-filled.我们使用的一种解决方法是检测 Chrome 对其自动填充的字段所做的背景颜色更改。 Chrome colors the background of auto-filled fields yellow, and this change is always visible to Javascript even when the value is not. Chrome 将自动填充字段的背景着色为黄色,即使值不存在,Javascript 也始终可以看到此更改。 Detecting this in Javascript lets us know that the field was auto-filled with a value, even though we see the value as blank in Javascript.在 Javascript 中检测到这一点让我们知道该字段自动填充了一个值,即使我们在 Javascript 中看到该值是空白的。 In our case, we have a login form where the submit button is not enabled until you fill in something in the password field, and detecting either a value or the auto-fill background-color is good enough to determine that something is in the field.在我们的例子中,我们有一个登录表单,其中提交按钮在您在密码字段中填写某些内容之前不会启用,并且检测值或自动填充背景颜色足以确定该字段中有某些内容. We can then enable the submit button, and clicking the button (or pressing enter) instantly makes the password field value visible to Javascript because interacting with the page fixes the problem, so we can proceed normally from there.然后我们可以启用提交按钮,单击按钮(或按 Enter 键)立即使密码字段值对 Javascript 可见,因为与页面交互修复了问题,因此我们可以从那里正常进行。

Working Answer as of July 8, 2016截至 2016 年 7 月 8 日的工作答案

Adam correctly stated this is a bug (or intended behavior).亚当正确地指出这是一个错误(或预期的行为)。 However, none of the previous answers actually say how to fix this, so here is a method to force Chrome to treat the autocompleted value as a real value.但是,之前的答案实际上都没有说明如何解决此问题,因此这里有一种方法可以强制 Chrome 将自动完成的值视为真实值。

Several things need to happen in order, and this needs to only run in Chrome and not Firefox, hence the if .有几件事需要按顺序发生,这需要只在 Chrome 而不是 Firefox 中运行,因此if

First we focus on the element.首先我们关注元素。 We then create a new TextEvent , and run initTextEvent , which adds in a custom string that we specify (I used "@@@@@") to the beginning of the value.然后我们创建一个新的TextEvent ,并运行initTextEvent ,它将我们指定的自定义字符串(我使用“@@@@@”)添加到值的开头。 This triggers Chrome to actually start acting like the value is real.这会触发 Chrome 实际上开始表现得好像值是真实的。 We can then remove the custom string that we added, and then we unfocus.然后我们可以删除我们添加的自定义字符串,然后我们取消焦点。


Code:代码:

input.focus();

var event = document.createEvent('TextEvent');

if ( event.initTextEvent ) {

    event.initTextEvent('textInput', true, true, window, '@@@@@');

    input.dispatchEvent(event);

    input.value = input.value.replace('@@@@@','');

}

input.blur();

Edit August 10, 2016编辑 2016 年 8 月 10 日

This only works right now in Chrome on Windows and Android.这仅适用于 Windows 和 Android 上的 Chrome。 Doesn't work on OSX.不适用于 OSX。 Additionally, it will stop working at all in Sept 2016, according to:此外,根据以下信息,它将在 2016 年 9 月完全停止工作:

https://www.chromestatus.com/features/5718803933560832 https://www.chromestatus.com/features/57188​​03933560832

Also, I've opened a Chromium ticket.另外,我开了一张 Chromium 票。

https://bugs.chromium.org/p/chromium/issues/detail?id=636425https://bugs.chromium.org/p/chromium/issues/detail?id=636425

As of August 12, a member of the Chrome team said on the above ticket that the behavior won't be changing because they don't consider it a bug.截至 8 月 12 日,Chrome 团队的一名成员在上述工单上表示,行为不会改变,因为他们不认为这是一个错误。

Long-term Work-Around Suggestion:长期解决建议:

That said, the current behavior has been tweaked from when it was first implemented.也就是说,当前的行为已经从第一次实施时进行了调整。 The user no longer has to interact with the password input for the value to be reported.用户不再需要与要报告的值的密码输入进行交互。 The user now just needs to interact (send a mouse or keyboard event) with any part of the page.用户现在只需要与页面的任何部分进行交互(发送鼠标或键盘事件)。 That means that while running validation on pageload still won't work, clicking on a submit button WILL cause Chrome to correctly report the password value.这意味着虽然在页面加载上运行验证仍然不起作用,但单击提交按钮将导致 Chrome 正确报告密码值。 The work-around then, is to revalidate all inputs that might be autocompleted, if that is what you are trying to do, on submit.解决方法是在提交时重新验证所有可能会自动完成的输入(如果这是您尝试执行的操作)。


Edit December 13, 2016: 2016 年 12 月 13 日编辑:

A new Chromium ticket has been opened and is being received better.一张新的 Chromium 票已打开,并且收到的效果更好。 If interested in changing this behavior of Chrome's, please star this new ticket:如果有兴趣改变 Chrome 的这种行为,请在这张新票上加注星标:

https://bugs.chromium.org/p/chromium/issues/detail?id=669724https://bugs.chromium.org/p/chromium/issues/detail?id=669724

Continuing from what Andy Mercer said , here's my work around.继续Andy Mercer 所说的,这是我的工作。 Like a lot of people, I don't need the actual password value.像很多人一样,我不需要实际的密码值。 I really just need to know that the password box has been autofilled, so that I can display the proper validation messages.我真的只需要知道密码框已自动填充,以便我可以显示正确的验证消息。

Personally, I would not use suggested solution to detect the background color change cause by Chrome's autofill.就个人而言,我不会使用建议的解决方案来检测 Chrome 自动填充导致的背景颜色变化。 That approach seems brittle.这种方法似乎很脆弱。 It depends on that yellow color never changing.这取决于永远不会改变的黄色。 But that could be changed by an extension and be different in another Blink based browser (ie. Opera).但这可以通过扩展程序进行更改,并且在另一个基于 Blink 的浏览器(即 Opera)中会有所不同。 Plus, there's no promise Google wont use a different color in the future.另外,不能保证 Google 将来不会使用不同的颜色。 My method works regardless of style.无论风格如何,我的方法都有效。

First, in CSS I set the content of the INPUT when the -webkit-autofil pseudo-class is applied to it:首先,在 CSS 中,当应用-webkit-autofil伪类时,我设置了INPUT的内容:

input:-webkit-autofill {
  content: "\feff"
}

Then, I created a routine to check for the content to be set:然后,我创建了一个例程来检查要设置的内容:

const autofillContent = `"${String.fromCharCode(0xFEFF)}"`;
function checkAutofill(input) {
    if (!input.value) {
        const style = window.getComputedStyle(input);
        if (style.content !== autofillContent)
            return false;
    }

    //the autofill was detected
    input.classList.add('valid'); //replace this. do want you want to the input
    return true;
}

Lastly, I polled the input to allow the autofill time to complete:最后,我轮询input以允许自动填充时间完成:

const input = document.querySelector("input[type=password]");

if (!checkAutofill(input)) {
    let interval = 0;
    const intervalId = setInterval(() => {
        if (checkAutofill(input) || interval++ >= 20)
            clearInterval(intervalId);
    }, 100);
}

Here's my solution to this issue:这是我对这个问题的解决方案:

$(document).ready(function(){
  if ( $("input:-webkit-autofill").length ){
    $(".error").text("Chrome autofill detected. Please click anywhere.");
  }
});

$(document).click(function(){
  $(".error").text("");
});

Basically, clicking makes the input visible to the user, so I ask the user to click and when they do, I hide the message.基本上,点击使输入对用户可见,所以我要求用户点击,当他们点击时,我隐藏消息。

Not the most elegant solution but probably the quickest.不是最优雅的解决方案,但可能是最快的。

$(document).ready   

does not wait for autofill of browser, it should be replaced by不等待浏览器的自动填充,它应该被替换为

$(window).on("load", checkforAutoFill())

Another option as of Dec. 16 / Chrome 54 12 月 16 日/Chrome 54 的另一种选择

I can't get the value of the password field, but, after "a short while", I can get the length of the password by selecting it, which is sufficient for me to enable the submit button.我无法获取密码字段的值,但是,在“一小会儿”之后,我可以通过选择它来获取密码的长度,这足以让我启用提交按钮。

setTimeout(function() {
  // get the password field
  var pwd = document.getElementById('pwd');
  pwd.focus();
  pwd.select();
  var noChars = pwd.selectionEnd;
  // move focus to username field for first-time visitors
  document.getElementById('username').focus()
  if (noChars > 0) {
    document.getElementById('loginBtn').disabled = false;
  }
}, 100);

The workaround specified by Adam: Adam 指定的解决方法:

... detect the background color change that Chrome makes to fields that it has auto-filled. ...检测 Chrome 对其自动填充的字段所做的背景颜色更改。 Chrome colors the background of auto-filled fields yellow, and this change is always visible to Javascript even when the value is not. Chrome 将自动填充字段的背景着色为黄色,即使值不存在,Javascript 也始终可以看到此更改。 Detecting this in Javascript lets us know that the field was auto-filled with a value, even though we see the value as blank in Javascript在 Javascript 中检测到这一点让我们知道该字段已自动填充了一个值,即使我们在 Javascript 中将该值视为空白

I did like this:-我确实喜欢这样:-

getComputedStyle(element).backgroundColor === "rgb(250, 255, 189)"

where rgb(250, 255, 189) is the yellow color Chrome applies to auto filled inputs.其中 rgb(250, 255, 189) 是 Chrome 应用于自动填充输入的黄色。

I have found a solution to this issue that works for my purposes at least.我找到了一个解决这个问题的方法,它至少对我有用。

I have a login form that I just want to hit enter on as soon as it loads but I was running into the password blank issue in Chrome.我有一个登录表单,我只想在它加载后立即按回车键,但我在 Chrome 中遇到了密码空白问题。

The following seems to work, allowing the initial enter key to fail and retrying again once Chrome wakes up and provides the password value.以下似乎有效,允许初始输入键失败并在 Chrome 唤醒并提供密码值后再次重试。

$(function(){

    // bind form submit loginOnSubmit
    $('#loginForm').submit(loginOnSubmit);

    // submit form when enter pressed on username or password inputs
    $('#username,#password').keydown(function(e) {
        if (e.keyCode == 13) {
            $('#loginForm').submit(e);
            return false;
        }
    });

});

function loginOnSubmit(e, passwordRetry) {

    // on submit check if password is blank, if so run this again in 100 milliseconds
    // passwordRetry flag prevents an infinite loop
    if(password.value == "" && passwordRetry != true)
    {
        setTimeout(function(){loginOnSubmit(e,true);},100);
        return false;
    }

    // login logic here
}

Just wrote an angular directive related to this.刚刚写了一个与此相关的角度指令。 Ended up with the following code:最终得到以下代码:

if ('password' == $attrs.type) {
      const _interval = $interval(() => { //interval required, chrome takes some time to autofill
          if ($element.is(':-webkit-autofill')) { //jQuery.is()
              //your code
              $interval.cancel(_interval);
          }
      }, 500, 10); //0.5s, 10 times
}

ps: it wont detect 100% of the times, chrome might take longer than 5 seconds to fill the input. ps:它不会检测到 100% 的时间,chrome 可能需要超过 5 秒来填充输入。

$element.is("*:-webkit-autofill")

为我工作

It is amazing that in 2021 this has not been solved in Chrome yet, I have had issue with autocomplete since 2014 and still nothing.令人惊讶的是,到 2021 年,Chrome 还没有解决这个问题,自 2014 年以来,我遇到了自动完成问题,但仍然没有。

Chrome functionality autocomplete is misleading for the user, I do not know what are they trying to achieve but does not look good. Chrome 功能自动完成对用户具有误导性,我不知道他们试图实现什么但看起来不太好。

As it is now, form appears showing auto-completed text (user/email/pass) to the user, but in the background html - values are not inside of the elements.现在,表单出现向用户显示自动完成的文本(用户/电子邮件/传递),但在后台 html - 值不在元素内。 As values are not in fields custom validation will disable submit button.由于值不在字段中,自定义验证将禁用提交按钮。

Script that checks fields values will say value is null, which is even more confusing for the user as s/he can see text is there, and can assume it is valid, leading to confusing delete-one insert one character.检查字段值的脚本会说 value 为 null,这对用户来说更加混乱,因为他/她可以看到文本在那里,并且可以假设它是有效的,从而导致混淆 delete-one 插入一个字符。 (Embarrassingly, I have to admit I did not know that you need to click in the body of the HTML, so I wonder how many users don not know the same) (尴尬的是,我不得不承认我不知道您需要在 HTML 正文中单击,所以我想知道有多少用户不知道相同的内容)

In my case I wanted to have empty field always and then fount out it is just needlessly spent time to make it work.在我的情况下,我希望总是有空的领域,然后发现它只是不必要地花费时间让它工作。

If we try autocomplete=off we will discover that it is not working.如果我们尝试autocomplete=off我们会发现它不起作用。 And to validate fields and let say enable button we need to do some trickery.为了验证字段并假设启用按钮,我们需要做一些技巧。 (Have in mind that I have tried autocomplete=password new-password) and other type of Hocus-Pocus trickery from official resource . (请记住,我已经尝试过autocomplete=password new-password)和来自官方资源的其他类型的 Hocus-Pocus 诡计。

At the end I have done this.最后我做到了。

<script>
  $('#user').value = ' '; //one space
  $('#pass').value = ' '; // one space - if this is empty/null it will autopopulate regardless of on load event
  window.addEventListener('load', () => {
      $('#user').value = ''; // empty string
      $('#pass').value = ''; // empty string 
  });
</script>

So, it will blink for a split second in some cases in password field with * not ideal but :/ ...因此,在某些情况下,它会在密码字段中闪烁一秒钟, *不理想但 :/ ...

With Angular, the new behaviour in Chrome (only allowing autofilled values to be read after the user has interaction with the page) manifests itself as an issue when you're using Angular's validation functionality in certain scenarios (for eg using standard method/action attributes on the form).使用 Angular,Chrome 中的新行为(仅允许在用户与页面交互后读取自动填充值)在某些情况下(例如使用标准方法/操作属性)使用 Angular 的验证功能时会显示为问题在表格上)。 As the submit handler is executed immediately, it does not allow the form validators to capture the autofilled values from Chrome.由于提交处理程序是立即执行的,因此它不允许表单验证器从 Chrome 捕获自动填充的值。

A solution I found for this to explicitly call the form controllers $commitViewValue function in the submit handler to trigger a revalidation before checking form.$valid or form.invalid etc.我找到的一个解决方案是在提交处理程序中显式调用表单控制器$commitViewValue函数以在检查form.$validform.invalid等之前触发重新验证。

Example:例子:

function submit ($event) {
    // Allow model to be updated by Chrome autofill
    // @see http://stackoverflow.com/questions/35049555/chrome-autofill-autocomplete-no-value-for-password
    $scope.loginModule.$commitViewValue();

    if ($scope.loginModule.$invalid) {
        // Disallow login
        $scope.loginModule.$submitted = true;
        $event.preventDefault();
    } else {
        // Allow login
    }
}

Although this is working for us so far, I would be very interested if someone has found another, more elegant work around for the issue.尽管到目前为止这对我们有用,但如果有人找到另一个更优雅的解决方法来解决这个问题,我会非常感兴趣。

Chrome's intended behavior is that an auto-filled password has an empty value in the DOM until the user interacts with the frame in some way, at which point chrome actually populates the value. Chrome 的预期行为是自动填充的密码在 DOM 中具有空value ,直到用户以某种方式与框架交互,此时 chrome 实际填充该值。 Until this point any client side validation or attempt to ajax submit the form will see the password as empty.在此之前,任何客户端验证或尝试 ajax 提交表单都会看到密码为空。

This 'populate password value on frame interaction' behavior is inconsistent.这种“在框架交互时填充密码值”行为不一致。 I've found when the form is hosted in a same-origin iframe it only operates on the first load, and never on subsequent loads.我发现当表单托管在同源 iframe 中时,它只在第一次加载时运行,而不会在后续加载中运行。

This is most evident on ajax forms where the autocomplete password populates on first load, however if that password is invalid and the ajax submission re-renders the form DOM, the autocompleted password re-appears visually but the value is never populated, irrespective of interaction.这在首次加载时自动完成密码填充的 ajax 表单上最为明显,但是如果该密码无效并且 ajax 提交重新呈现表单 DOM,自动完成的密码会重新出现在视觉上,但无论交互如何,都不会填充该value .

None of the workarounds mentioned such as triggering blur or input events worked in this scenario.提到的任何变通方法(例如触发blurinput事件)都不适用于这种情况。 The only workaround I've found is to reset the password field value after the ajax process re-renders the form, eg:我发现的唯一解决方法是在 ajax 进程重新呈现表单后重置密码字段值,例如:

$('input[type="password"]').val("");

After the above, Chrome actually autocompletes the password again but with the value actually populated.在上述之后,Chrome 实际上会再次自动完成密码,但实际填充了该value

In my current use case I'm using ASP.NET's Ajax.BeginForm and use the above workaround in the AjaxOptions.OnSuccess callback.在我当前的用例中,我使用 ASP.NET 的 Ajax.BeginForm 并在 AjaxOptions.OnSuccess 回调中使用上述解决方法。

var txtInput = $(sTxt);
txtInput.focus();
txtInput.select();

This solution worked in my case.这个解决方案在我的情况下有效。 Using jQuery 3.1.1.使用 jQuery 3.1.1。

如果您想让输入被视为已完成,请尝试在其上触发blur$('input[type="password"]').blur();

The autocomplete feature has successfully disabled.自动完成功能已成功禁用。 It Works!有用!

[HTML] [HTML]

<div id="login_screen" style="min-height: 45px;">
   <input id="password_1" type="text" name="password">
</div>

[JQuery] [JQuery]

$("#login_screen").on('keyup keydown mousedown', '#password_1', function (e) {
    let elem = $(this);

    if (elem.val().length > 0 && elem.attr("type") === "text") {
        elem.attr("type", "password");
    } else {
        setTimeout(function () {
            if (elem.val().length === 0) {
                elem.attr("type", "text");
                elem.hide();
                setTimeout(function () {
                    elem.show().focus();
                }, 1);
            }
        }, 1);
    }

    if (elem.val() === "" && e.type === "mousedown") {
        elem.hide();
        setTimeout(function () {
            elem.show().focus();
        }, 1);
    }

});

To me none of this solutions seemed to work.对我来说,这些解决方案似乎都不起作用。

I think this is worth mentioning that if you want to use it for CSS styling you sould use -webkit-autofill property like this:我认为值得一提的是,如果您想将它用于 CSS 样式,您应该使用 -webkit-autofill 属性,如下所示:

input:-webkit-autofill~.label,
input:-webkit-autofill:hover~.label, 
input:-webkit-autofill:focus~.label
input:focus~.label,
input:not(.empty)~.label {
  top: -12px;
  font-size: 12px;
  color: rgba(0, 0, 0, .4);
  font-weight: 600
}

You mentioned:你提到:

If you click somewhere on the page no matter where the value of the input type="password" will be filled.如果你点击页面上的某个地方,无论输入类型=“密码”的值在哪里都会被填充。

Which is why I simply use $('body').click();这就是为什么我简单地使用$('body').click(); to simulate this first click, after which the value is available in JavaScript.模拟第一次点击,之后该值在 JavaScript 中可用。

Also, I set autocomplete="new-password" on my signup form password field, so that the field is not autofilled and users have to fill in a new password.另外,我在注册表单密码字段上设置了autocomplete="new-password" ,这样该字段就不会自动填充,用户必须填写新密码。

See this Google Developers page for more information.有关详细信息,请参阅此 Google Developers 页面

My solution comparing my css to the chrome autocomplete color...我的解决方案将我的 css 与 chrome 自动完成颜色进行比较...

$('input, select, textarea').each(function(){
    var inputValue = $(this).val();
    if ( inputValue != "" || $(this).css("background-color") != "rgba(255, 255, 255, 0)") {
        $(this).parents('.form-group').addClass('focused');
    }
});

I tried all the solutions and wasn't working for me so i came up with this.我尝试了所有解决方案,但对我不起作用,所以我想出了这个。 My problem is i have an input that move the placeholder top when it is filled, off course this is not working when Chrome autofill it.我的问题是我有一个输入,它在填充时移动占位符顶部,当然这在 Chrome 自动填充时不起作用。 Only tested in Chrome :仅在 Chrome 中测试:

 setTimeout(function () {
     var autofilled = document.querySelectorAll('input:-webkit-autofill');
         for (var i = 0; i < autofilled.length; i++) {
             Do something with your input autofilled
         }
 }, 200);

My version is 95.0.4638.69我的版本是 95.0.4638.69

I'm facing simillar issue and I solved it by changing my form's name from "login-form" to another name which does not mean anything and solve it.我面临着类似的问题,我通过将表单的名称从“登录表单”更改为另一个没有任何意义的名称来解决它并解决它。 Reason why I didn't remove name attribute is because if I remove name attribute Chrome will look up to id attribute and do the same thing.我没有删除 name 属性的原因是因为如果我删除 name 属性,Chrome 将查找 id 属性并执行相同的操作。

Option using onanimationstart event (ReactJs) - Mar 22使用 onanimationstart 事件的选项 (ReactJs) - 3 月 22 日

I could avoid the needing of verifying periodically if the input was autofilled, as described above using setInterval , by taking advantage of the onanimationstart event .通过利用onanimationstart 事件,我可以避免定期验证输入是否自动填充,如上所述使用setInterval I don't know if it will work in every case, but definitely did the trick for me.我不知道它是否适用于所有情况,但绝对对我有用。

I'll provide a code sample in ReactJs, it may be explanatory enough to be transposed to another context.我将在 ReactJs 中提供一个代码示例,它可能具有足够的解释性,可以转移到另一个上下文中。

First of all, is necessary to add in your input the onAnimationStart property, in such a way that the event is passed as parameter to your function, as following below.首先,有必要在您的输入中添加onAnimationStart属性,以便将事件作为参数传递给您的 function,如下所示。

<input
 className={componentClass}
 placeholder={placeholder}
 onChange={handleChange}
 onFocus={onFocus}
 onMouseEnter={onHover}
 onMouseLeave={onHover}
 onBlur={onBlur}
 disabled={disabled}
 name={name}
 value={value}
 onAnimationStart={e => this.onAnimationStart(e)}
/>

Then let's proceed to the onAnimationStart function body.然后让我们继续执行onAnimationStart主体。

onAnimationStart(event) {   
   // on autofill animation
   if (event.animationName === 'onAutoFillStart') {
     event.target?.labels[0].classList.add('grm-form__isAutofilled');
   }
 }

First I verified if the animation name was actually the auto-fill animation, and then I added a class to the first label of my input, this is my use case but can be adapted to solve different problems.首先,我验证了 animation 名称是否实际上是自动填充的 animation,然后我在输入的第一个 label 中添加了 class,这是我的用例,但可以适应以解决不同的问题。

It's not a bug.这不是一个错误。 It's a security issue.这是一个安全问题。 Imagine if one could just use javascript to retrieve autofilled passwords without the users' acknowledgment.想象一下,如果可以在没有用户确认的情况下使用 javascript 来检索自动填充的密码。

Just set the autocomplete attribute to username for the username field and new-password for the password field;只需将用户名字段的自动完成属性设置为 username 和密码字段的 new-password ;

<input type="text" id="username" autocomplete="username">
<input type="password" id="password" autocomplete="new-password" >

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM