Chrome 自动填充/自动完成没有密码值 [英] Chrome Autofill/Autocomplete no value for password

查看:58
本文介绍了Chrome 自动填充/自动完成没有密码值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您保存了某些站点的用户名和密码时,Chrome 会自动填充该用户名和密码,但是如果您尝试获取密码输入字段的值,即使那里有值,它也是空字符串 ******.

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 ******.

如果您单击页面上的某处,则无论 input type="password" 的值在哪里都会被填充.

If you click somewhere on the page no mater where the value of the input type="password" will be filled.

这是 html 结构的 Fiddle user/passconsole.log命令.它在这里看不到,但可以在每个有登录表单的页面上复制,并且在页面加载时自动填充用户名和密码.如果您在点击网站上的任何其他地方之前检查该字段的值,它将是空字符串.

This is Fiddle user/pass of the structure of the html and the console.log command. 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.

在 Firefox 或 Internet Explorer 中不是这种情况,它会用密码填充 input 元素的值.

This is not the case in Firefox or Internet Explorer it will fill the value of the input element with the password.

我使用的是 Windows 7 Ultimate 64 位操作系统,Google Chrome 版本为 48.0.2564.97 m

I am using Windows 7 Ultimate 64-bit OS and Google Chrome version is 48.0.2564.97 m

这是正常行为,错误还是?

Is this normal behavior, bug or?

更新:

如果您点击 F5 重新加载页面并检查密码字段,密码的值将在那里.如果您点击 Chrome 左上角的重新加载按钮,密码字段的值将为空字符串.

If you click on F5 to reload the page and inspect the password field the value for password will be there. If you click the reload button in Chrome in top left corner the value for the password field will be empty string.

推荐答案

这似乎是 Chrome 中的一个错误.当 Chrome 在初始页面加载(但不是刷新)时自动填充密码时,该值会出现在屏幕上的表单字段中,但在 Javascript 中查询 passwordField.value 会返回一个空字符串.如果您依赖于在 Javascript 中看到该值,这将阻止您这样做.一旦用户在页面上执行任何其他操作,例如单击页面上的任意位置,该值就会突然对 Javascript 可见.

This seems to be a bug in 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. If you depend on seeing that value in Javascript, this prevents you from doing so. Once the user does any other action on the page, such as clicking anywhere on the page, the value suddenly becomes visible to Javascript.

我实际上并不能 100% 确定这是否是一个错误,或者是否有这样做的安全原因,例如通过欺骗浏览器填写密码来防止隐藏框架窃取您的密码.

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.

我们使用的一种解决方法是检测 Chrome 对其自动填充的字段所做的背景颜色更改.Chrome 将自动填充字段的背景着色为黄色,即使值不存在,Javascript 也始终可以看到此更改.在 Javascript 中检测到这一点让我们知道该字段已自动填充了一个值,即使我们在 Javascript 中将该值视为空白.在我们的例子中,我们有一个登录表单,其中提交按钮在您在密码字段中填写某些内容之前不会启用,并且检测值或自动填充背景颜色足以确定该字段中有某些内容.然后我们可以启用提交按钮,点击按钮(或按 Enter 键)立即使密码字段值对 Javascript 可见,因为与页面交互修复了问题,因此我们可以从那里正常进行.

A workaround that we have used is to detect the background color change that Chrome makes to fields that it has auto-filled. Chrome colors the background of auto-filled fields yellow, and this change is always visible to Javascript even when the value is not. 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. 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.

这篇关于Chrome 自动填充/自动完成没有密码值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆