我们使用 WebAuthn。虽然,有些设备会抛出异常NotSupportedError: The user agent does not support public key credentials.
以下是我们检查平台身份验证功能是否可用的方法:
async function isWebAuthn() {
return Boolean(
navigator.credentials &&
navigator.credentials.create &&
navigator.credentials.get &&
self.PublicKeyCredential &&
self.PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable &&
await self.PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable()
);
}
每次我们尝试调用时,我们都会看到至少有两个设备抛出异常navigator.credentials.create()
。
Mozilla/5.0 (Linux; Android 9; ONEPLUS A3003) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.136 Mobile Safari/537.36
Mozilla/5.0 (Linux; Android 9; LG-H930) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.116 Mobile Safari/537.36
这是电话:
await navigator.credentials.create({
publicKey: {
authenticatorSelection: {
authenticatorAttachment: "platform",
requireResidentKey: false,
userVerification: "required"
},
challenge: challenge,
rp: { id: document.domain, name: name },
user: {
id: id,
name: name,
displayName: displayName
},
pubKeyCredParams: [
{ type: "public-key", alg: -7 },
{ type: "public-key", alg: -257 }
]
}
});
如何避免浏览器抛出该异常?