← Blog 5 min read

WebOTP API: When a Website Can Use an SMS Code

WebOTP API: When a Website Can Use an SMS Code

Entering a one-time code can feel like a simple ritual: wait for a text, copy six digits, return to the browser. On a supported phone, WebOTP can make that step quicker. The important question is not whether a site can magically read your messages. It cannot. The question is which code is offered, under what conditions, and whether you trust the page that receives it.

How WebOTP handles an SMS code

WebOTP is a browser API for one-time codes sent by SMS. A site starts a request while its verification page is open. Its server sends a specially formatted message that includes the site’s domain and the code. On a supported device, the browser can recognize that match and ask for your consent before giving the code to the requesting page. The site then submits the code to its server, which must verify it.

That is narrower than reading an inbox. The browser is waiting for an appropriately formatted, origin-bound message for this verification flow; it is not handing a website your message history. MDN’s WebOTP API guide describes the format, the consent step, and the fact that browser support varies. A desktop browser generally does not have the same direct access to incoming phone SMS as a mobile device, so do not expect this flow to work everywhere.

The final line of an eligible SMS identifies the website domain alongside the code. This binding helps the browser present the code to the intended origin rather than a lookalike page. It does not make every texted code intrinsically secure or every page trustworthy. You still need to inspect the address bar and understand why the site is asking you to sign in.

WebOTP is not the same as ordinary autofill

There is a closely related, simpler route: a form field marked autocomplete="one-time-code". A browser or operating system may offer to fill an origin-bound SMS code in that field without the site using the WebOTP JavaScript API. The MDN guide to one-time passwords notes that this standardized message format can support autocomplete across browsers. If a site only needs a convenient suggestion, it may not need programmatic access to the code at all.

With WebOTP, the page receives the code after the browser’s consent flow and can choose to submit the form automatically. With autofill, the user is usually more directly involved in selecting the suggestion and submitting. Neither mechanism should be confused with a browser storing your account password. They are ways to complete a particular verification attempt, not a long-term identity system.

Where the security boundary is

SMS codes have familiar weaknesses. A stolen phone, SIM-swap attack, compromised mobile account, or social engineering conversation can put a code in the wrong hands. A scammer may ask you to relay a code while they initiate a sign-in elsewhere. Origin binding helps with one specific problem—matching the message to the requesting site—but cannot fix those other failure modes.

Most importantly, never read out or forward a code because someone contacted you unexpectedly. If you did not begin the sign-in yourself, do not approve the prompt or enter the code. If the site address looks different from what you expected, close the page and navigate to the service yourself. A polished sign-in screen is not proof of authenticity.

For accounts that offer them, passkeys can provide phishing-resistant authentication without relying on an SMS delivery channel. The right choice depends on the service and your recovery options, but a texted code should not be treated as the strongest possible proof of identity. MDN cautions against using SMS OTP alone to establish a new session.

What about codes inside embedded sign-in frames?

Some services put a sign-in form inside another site’s page. WebOTP can support certain cross-origin iframe cases, but the message needs to name both the top-level site and the embedded origin in the prescribed format, and the embedding page must allow the feature through Permissions Policy. That is a deliberately more specific arrangement than a random embedded widget reading any SMS. The web.dev explanation of cross-origin WebOTP details the two-origin message format.

As a user, the larger lesson is to notice the context. If you are signing in through a third-party widget, know which service is asking for your code. A browser’s permission or consent prompt is a moment to check the site, not a reason to click automatically. If the flow feels surprising, cancel it and use the service’s own website or app.

A calmer sign-in habit

Start authentication from a bookmark or a known address, not a link in an unsolicited message. Check the domain before accepting a code suggestion. Do not share codes with support agents or strangers; genuine services do not need you to dictate a live sign-in code over chat. When available, consider a passkey or an authenticator-based second factor, and keep account recovery details current.

WebOTP is a convenience layer with meaningful boundaries, not a blanket SMS-reading privilege. Its best use removes friction from a sign-in you initiated while preserving the chance to notice where the code is going. For a broader look at identity prompts, see our FedCM sign-in explainer; for everyday browser controls, start with our permissions guide.

Browse with more intention

Noorani brings prayer times, Qibla, tracker blocking, and privacy into one calm desktop browser built for how Muslims live online.

Download Noorani