我们使用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 }
]
}
});
如何避免浏览器抛出该异常?