4

我正在使用新的 PasswordCredential API 并创建了这段代码。它正在工作。但是对于某些用户,它会引发此错误The user agent does not support public key credentials.

if (window.PasswordCredential) {
    navigator.credentials.get({
        password: true,
        mediation: 'optional'
    }).then(credential => {
        if (credential) {
        if (credential.type === 'password') {
            // authenticate the user with obtained credentials
        }
    });
}

尽管我没有使用该 API,但我们的许多用户都收到了该错误。那么,我是否应该像这样检查这两种情况:

if (window.PasswordCredential && typeof(PublicKeyCredential) != "undefined" ) {

如果是这样,我为什么要对两者都进行检查?

4

0 回答 0