[英]Google Smartlock: what to do when PromiseStatus: pending via Javascript in console
we are integrating Google Smartlock.我们正在集成 Google Smartlock。 Every time we run the JS code to enable Smart lock on 1 screen it does nothing at all.每次我们运行 JS 代码以在 1 个屏幕上启用智能锁定时,它什么都不做。 And when we trigger it manually we only see this in console log.当我们手动触发它时,我们只能在控制台日志中看到这一点。
Promise {[[PromiseStatus]]: "pending", [[PromiseValue]]: undefined}
javascript is like this javascript是这样的
<script>
window.onload=function(e){
var debug = true;
var always = function() { console.log('Promise resolved: but dont understand how should process: we want/need to login') }
navigator.credentials.get({password: true, unmediated: true, }).then(function(cred) {
if (cred) {
if (cred.type == 'password') {
var form = new FormData();
cred.additionalData = form;
var url = 'domain.com/login';
fetch(url, {method: 'POST', credentials: cred }).then(function(response) {
if (response.status == 202) {
if (debug) { console.log('Login success; reload stopped'); exit; }
window.location.reload();
}
if (debug) { console.log('Server status: ' + response.status); }
return;
}).catch(function(err) { console.log('Smartlock Ajax error:'+ err);
}).then(always, always);
} // can add federated here
} else if (typeof cred === "undefined") {
// user clicks cancel or no credentials found
var expiry = new Date(); expiry.setDate(expiry.getDate() + (1/3600*30));
document.cookie="dontshowagain=true; expires=" + expiry.toGMTString();
}
});
}
</script>
Question : Does anyone know what is happening here?问题:有谁知道这里发生了什么?
I tested with 1 saved passwd, with 2 saved passwd's.我测试了 1 个保存的密码,2 个保存的密码。 We do see the small key icon next to the URL in Chrome.我们确实在 Chrome 中的 URL 旁边看到了小钥匙图标。 But it doesn't popup or do anything.但它不会弹出或做任何事情。
Help/advise appreciated帮助/建议表示赞赏
References: https://support.google.com/accounts/answer/6160273?hl=en参考资料: https : //support.google.com/accounts/answer/6160273?hl=en
It looks like you're requesting unmediated: true
which forces the browser to not show the account selector UI.看起来您正在请求unmediated: true
,这会强制浏览器不显示帐户选择器 UI。
When you have more than one credentials stored or one credential that requires user mediation, get(...)
returns undefined
unless you allow the mediation ( unmediated: false
which is default).当您存储了多个凭据或一个需要用户中介的凭据时,除非您允许中介( unmediated: false
,这是默认值),否则get(...)
将返回undefined
。
Note: Your credentials should require mediation when the user signs out of an account ( navigator.credentials.requireUserMediation()
).注意:当用户注销帐户 ( navigator.credentials.requireUserMediation()
) 时,您的凭据应该需要中介。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.