Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect if the browser has support for webauthn

Tags:

webauthn

Webauthn is currently only supported in a limited number of devices https://caniuse.com/#search=webauthn.

In JavaScript I want to be able to detect if the users browser has support before offering them an sign-in or join form.

Checking for navigator.credentials seems to work but is it the right way to check for this support?

if(!navigator.credentials) {
  alert('fail');
}
like image 953
Bill Avatar asked Oct 16 '25 13:10

Bill


1 Answers

By checking navigator.credentials you're checking that the browser supports Credentials Management API, which is more than just WebAuthn.

Credential Management API so far supports 3 type of credentials, FederatedCredential, PasswordCredential and PublicKeyCredential.

WebAuthn is built on top of the PublicKeyCredential interface. See https://www.w3.org/TR/webauthn/#iface-pkcredential.

So what you need is:

if (typeof PublicKeyCredential === "undefined") {
    alert('fail');
}

That's why when you ask the browser to create a "WebAuthn credential", you need to specify the public key type: navigator.credentials.create({ "publicKey": { ... } }), see https://developer.mozilla.org/en-US/docs/Web/API/CredentialsContainer/create#Parameters.

like image 151
grzuy Avatar answered Oct 18 '25 23:10

grzuy