Limited support Limited browser support. Check compatibility before use.

Browser support

Feature Desktop Mobile
Chrome
Edge
Firefox
Safari
Chrome Android
Safari iOS
OTPCredential
Experimental
93
93
84
HTML attribute
allow (otp-credentials)
Experimental
93
93
84
DOM API
get (otp option)
Experimental

`otp` option

93
93
84
code
Experimental

The code read-only property of the OTPCredential interface contains the one-time password (OTP).

93
93
84
Other
otp-credentials
Experimental

The HTTP Permissions-Policy header otp-credentials directive controls whether the current document is allowed to use the WebOTP API to request a one-time password (OTP) from a specially-formatted SMS message sent by the app's server, i.e., via {{domxref("CredentialsContainer.get", "navigator.credentials.get({otp: ..., ...})")}}.

93
93
88
1+Supported (version) Not supported Has note Sub-feature descriptions sourced from MDN Web Docs (CC BY-SA 2.5)

Syntax

JAVASCRIPT
navigator.credentials
  .get({
    otp: { transport: ["sms"] },
    signal: ac.signal,
  })
  .then((otp) => {
    input.value = otp.code;
    if (form) form.submit();
  })
  .catch((err) => {
    console.error(err);
  });

Use cases

  • Using WebOTP

    The OTPCredential interface of the WebOTP API is returned when a WebOTP navigator.

Cautions

  • Limited browser support. Check compatibility before use.

Implementation notes

  • Some APIs require a secure context (HTTPS) or user activation. Check the requirements before use.