Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PublicKeyCredential.getClientCapabilities - add #37734

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
---
title: "PublicKeyCredential: getClientCapabilities() static method"
short-title: getClientCapabilities()
slug: Web/API/PublicKeyCredential/getClientCapabilities_static
page-type: web-api-static-method
browser-compat: api.PublicKeyCredential.getClientCapabilities_static
---

{{APIRef("Web Authentication API")}}{{securecontext_header}}

The **`getClientCapabilities()`** static method of the {{domxref("PublicKeyCredential")}} interface returns a {{jsxref("Promise")}} that resolves with a {{jsxref("Map")}} that can be used to check whether or not particular WebAuthn Client capabilities and [extensions](/en-US/docs/Web/API/Web_Authentication_API/WebAuthn_extensions) are supported.

If the value of a given capability is present in the map, then `true` indicates that the capability is currently supported, and `false` indicates that it is not.
However if a key is not present for a particular capability, no assumptions can be made about the availability of the associated feature.

For an extension the assumptions are the same, but note that generally if an extension is implemented the value will be `true`.
Note however that even if the extension is supported by the client a particular authenticator may not support that extension, so RPs must not assume that this is a guarantee that the authenticator processing steps for that extension will be performed.
If the key is not present for an extension then a Relying Party (RP) can't assume that client processing steps for that extension will be carried out by this client or that the extension will be forwarded to the authenticator.

A WebAuthn Relying Party can evaluate these to offer appropriate workflows and experiences to users.

## Syntax

```js-nolint
PublicKeyCredential.getClientCapabilities()
```

### Parameters

None.

### Return value

A {{jsxref("Promise")}} that resolves to a {{jsxref("Map")}} of client capability strings and a boolean indicating whether or not the corresponding capability or extension is supported.

The client capability strings are:

- `conditionalCreate`
- : The WebAuthn Client is capable of conditional mediation for registration ceremonies.
- `conditionalGet`
- : The WebAuthn Client is capable of conditional mediation for authentication ceremonies.
This capability is equivalent to isConditionalMediationAvailable() resolving to true.
- `hybridTransport`
- : The WebAuthn Client supports usage of the hybrid transport.
- `passkeyPlatformAuthenticator`
- : The WebAuthn Client supports usage of a passkey platform authenticator, locally and/or via hybrid transport.
- `userVerifyingPlatformAuthenticator`
- : The WebAuthn Client supports usage of a user-verifying platform authenticator.
- `relatedOrigins`
- : The WebAuthn Client supports Related Origin Requests.
- `signalAllAcceptedCredentials`
- : The WebAuthn Client supports signalAllAcceptedCredentials().
- `signalCurrentUserDetails`
- : The WebAuthn Client supports signalCurrentUserDetails().
- `signalUnknownCredential`
- : The WebAuthn Client supports signalUnknownCredential().

The [web extension](/en-US/docs/Web/API/Web_Authentication_API/WebAuthn_extensions) strings are formatted by prefixing the [extension identifier](/en-US/docs/Web/API/Web_Authentication_API/WebAuthn_extensions#available_extensions) with the prefix `extension:`.
For example, the key `extension.appid` can be used to check if the [`appid` extension](/en-US/docs/Web/API/Web_Authentication_API/WebAuthn_extensions#appid) is supported.

### Exceptions

The returned {{jsxref("Promise")}} may be rejected with the following values:

- `NotAllowedError` {{domxref("DOMException")}}
- : The Web Authentication API is not allowed in the current browsing context.
For example, it might be blocked by a permission policy.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps be more specific as to which types of permission policy will block it? Maybe link to https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Permissions-Policy/publickey-credentials-create and/or https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Permissions-Policy/publickey-credentials-get?

I'm not sure if both of them block usage of getClientCapabilities(), or just one.

Copy link
Collaborator Author

@hamishwillee hamishwillee Jan 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to leave for now because it is unspecified. Asking in w3c/webauthn#2251, but I don't think this should block merging.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, that's fine.


## Examples

<!--
```js
PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable()
.then((available) => {
if (available) {
// We can proceed with the creation of a PublicKeyCredential
// with this authenticator
} else {
// Use another kind of authenticator or a classical login/password
// workflow
}
})
.catch((err) => {
// Something went wrong
console.error(err);
});
```

-->

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

<!--
## See also
-->
2 changes: 2 additions & 0 deletions files/en-us/web/api/publickeycredential/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ The **`PublicKeyCredential`** interface provides information about a public key

## Static methods

- {{domxref("PublicKeyCredential.getClientCapabilities_static", "PublicKeyCredential.getClientCapabilities()")}}
- : Returns a {{jsxref("Promise")}} that resolves with a {{jsxref("Map")}} that can be used to check whether or not particular client capabilities are supported.
- {{domxref("PublicKeyCredential.isConditionalMediationAvailable_static", "PublicKeyCredential.isConditionalMediationAvailable()")}}
- : Returns a {{jsxref("Promise")}} which resolves to `true` if conditional mediation is available.
- {{domxref("PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable_static", "PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable()")}}
Expand Down
Loading