OTPCredential: code property
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
The code
property of the OTPCredential
interface returns the one-time password.
Value
A string containing the one-time password.
Examples
The below code uses the value of code
to complete an input form element. See this code as part of a simple demo.
js
navigator.credentials
.get({
otp: { transport: ["sms"] },
signal: ac.signal,
})
.then((otp) => {
input.value = otp.code;
if (form) form.submit();
})
.catch((err) => {
console.error(err);
});
Specifications
Specification |
---|
WebOTP API # dom-otpcredential-code |
Browser compatibility
BCD tables only load in the browser