问题
We use WebAuthn. Although, some devices throw exceptions NotSupportedError: The user agent does not support public key credentials.
Here is how we check if platform auth feature is available:
async function isWebAuthn() {
return Boolean(
navigator.credentials &&
navigator.credentials.create &&
navigator.credentials.get &&
self.PublicKeyCredential &&
self.PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable &&
await self.PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable()
);
}
We see at least two devices which throw exceptions every time we try calling 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
Here is the call:
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 }
]
}
});
How to avoid browser throwing that exception?
来源:https://stackoverflow.com/questions/59939695/occasional-notsupportederror-exception-using-webauthn