OTPCredential.code
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
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.
navigator.credentials.get({
otp: { transport:['sms'] },
signal: ac.signal
}).then(otp => {
input.value = otp.code;
if (form) form.submit();
}).catch(err => {
console.log(err);
});
Specifications
Specification |
---|
WebOTP API # dom-otpcredential-code |
Browser compatibility
BCD tables only load in the browser