Javascript 检测是否在浏览器中的Chrome扩展中保存登录凭据
我试图让Chrome扩展自动登录网站(通过提交其登录表单),前提是用户的登录凭证保存在浏览器中 由于登录凭证(电子邮件/密码)是在网页加载后填充到表单中的,因此我在页面加载后使用JavaScriptJavascript 检测是否在浏览器中的Chrome扩展中保存登录凭据,javascript,google-chrome,browser,google-chrome-extension,Javascript,Google Chrome,Browser,Google Chrome Extension,我试图让Chrome扩展自动登录网站(通过提交其登录表单),前提是用户的登录凭证保存在浏览器中 由于登录凭证(电子邮件/密码)是在网页加载后填充到表单中的,因此我在页面加载后使用JavaScript间隔,正如建议的那样 因此,我的代码如下: //use 10 seconds interval waiting for the form to populate by the saved credentials: var waitSeconds = 0; var interval = setInter
间隔,正如建议的那样
因此,我的代码如下:
//use 10 seconds interval waiting for the form to populate by the saved credentials:
var waitSeconds = 0;
var interval = setInterval(function () {
var inputEmail = document.getElementById('email');
var inputPass = document.getElementById('password');
console.log(
'inputEmail:', inputEmail, '\n',
'inputPass:', inputPass, '\n',
'inputEmail.value:', inputEmail.value, '\n',
'inputPass.value:', inputPass.value, '\n',
'inputEmail.defaultValue:', inputEmail.defaultValue, '\n',
'inputPass.defaultValue:', inputPass.defaultValue, '\n',
);
if (inputPass.defaultValue || inputPass.value) {
console.log('login credentials are saved at the browser!');
clearInterval(interval);
//click the form submit button here;
} else {
console.log('waiting...');
if (waitSeconds < 10) {
waitSeconds++;
} else {
clearInterval(interval);
console.log('10 seconds passed, timeout!');
}
}
}, 1000);
但是对于inputmail.value
,inputPass.value
,inputmail.defaultValue
,inputPass.defaultValue
,有时我得到数据,有时什么也得不到!只是空值
我不知道是什么原因有时会发生,有时不会,但是,根据一些观察,我注意到每当我手动与页面交互时,它总是在控制台上填充值
手动人机交互可以通过以下方式进行(在页面的任意位置单击,手动聚焦输入,在10秒钟的时间间隔内单击F12打开开发工具等)
Chrome是否要求这种手动交互作为防止窃取保存的用户凭据的安全措施?我不知道
我尝试以编程方式模拟人与人之间的交互,例如:
$(inputEmail).keydown().keypress().keyup().blur().focus();
还考虑过使用document.execCommand('paste')
,在值后粘贴空格或其他内容,这是出于绝望的做法
我该怎么做才能始终获得凭据并具有一致的登录功能
有没有更好的方法可以代替这个 对我来说,听起来你应该把电子邮件和密码存储并检索到
如果我理解正确,页面仍然不会自动登录,直到至少单击一次扩展按钮以启动任何脚本。如果是这种情况,让popup.js使用window.open执行页面的启动和自动登录,例如
$(inputEmail).keydown().keypress().keyup().blur().focus();