GeoTech

Engineering / Case study

OTP autofill everywhere: iOS one-time-code, WebOTP, WhatsApp copy-code and Android one-tap

GeoTech Engineering · · 8 min read

UXAuthenticationWhatsAppAndroid

Most of our products sign people in with a phone number and a 6-digit code, usually sent by WhatsApp. Typing that code is the moment people give up: they switch apps, memorise six digits, switch back, mistype one. In October 2026 we set a rule for every product: a code screen that does not fill itself is not finished. This is the single script that does it on the web, the small native piece that does it in our Android apps, and the parts that still do not work.

157lines in the shared web script
9codebases using it
27offline checks, all passing
0calls needed from each page

TL;DR

The problem

Each platform has its own way of reading a code, and each one has conditions that are easy to miss:

Where the user isCode arrives byWhat can fill it
iPhone, Safari or an in-app browserSMSone-time-code suggestion from Messages
iPhoneWhatsAppNothing automatic. Copy button, then paste
Android ChromeSMSWebOTP, only with the @domain #code line
Android or desktop ChromeWhatsAppClipboard read when the user returns
Our Android appWhatsAppOne-tap / zero-tap, after a handshake
Our Android appSMSSMS User Consent sheet

On top of that, our users are in Egypt and the Gulf, where many keyboards type Arabic-Indic digits (٠١٢٣). A field that expects [0-9]{6} rejects a perfectly correct code typed on an Arabic keyboard.

Why the per-page approach failed

Before the rule, each product had some of this. One sign-up form had one-time-code; another had a hand-written paste handler; a partner sign-in had neither. Every new code screen (forgot password, phone change, a second login step) was a fresh chance to forget. Copying good code from page to page does not scale, because the next page is always written in a hurry.

So we went the other way: one script, included once in every layout, that finds code fields by itself. A page only has to mark its field, and the markup it needs is the markup it should have anyway.

The fix: one script, no page code

The field looks like this:

<input id="otp" name="otp" type="text"
       autocomplete="one-time-code" inputmode="numeric"
       pattern="[0-9]{6}" maxlength="6" required>

The script picks up any input[autocomplete="one-time-code"], plus a class or data attribute for older fields, and adds these behaviours.

1. Typing and pasting

Arabic-Indic and Persian digits become ASCII as they are typed, and anything that is not a digit is dropped. A paste is searched for the code, so pasting a whole WhatsApp message ("Your code is 123 456") still works. If the field is split into one box per digit, the code is spread across the boxes. The same path catches the iOS suggestion, which drops all six digits into the first box at once.

function extract(text, n) {
  const t = ascii(text).replace(/(\d)[ -](?=\d)/g, '$1');      // "123 456" → "123456"
  const m = new RegExp('(?:^|\\D)(\\d{' + n + '})(?!\\d)').exec(t);
  if (m) return m[1];                                             // an exact run of n digits wins
  const d = t.replace(/\D/g, '');
  return d.length === n ? d : '';
}

When the code is complete, the form submits itself, at most once every four seconds. A form can opt out with data-otp-autosubmit="off".

2. WebOTP on Android Chrome

While a code field is visible, the script holds an open navigator.credentials.get({ otp: { transport: ['sms'] } }) request with an AbortController. It aborts on submit and on leaving the page, and a MutationObserver restarts it when a hidden code step becomes visible. The browser only answers for an SMS that ends with @<the page's host> #<code>, so that line is part of the message format.

3. The WhatsApp copy-code button

WhatsApp authentication templates show a "Copy code" button. The user taps it and comes back to our tab. On visibilitychange and focus, the script asks the Permissions API about clipboard-read:

A code that has already been used is remembered, so returning to the tab later does not refill an old code.

4. Native: one-tap inside our Android apps

Our Android apps (DentX, Krown, Kauthar AI and others) are native shells around the web app. Right before a code is sent, the page calls a handshake that the shell forwards to native code. The native side does two things:

  1. It sends WhatsApp's OTP_REQUESTED broadcast with a PendingIntent that identifies our app. If the template is set to one-tap or zero-tap and lists our package and signing hash, WhatsApp shows "Autofill" or passes the code straight to the app. We accept the code only if that PendingIntent was created by WhatsApp itself.
  2. It starts Android's SMS User Consent, so an SMS code shows Google's own "allow this app to read this message?" sheet. We launch that sheet only if it resolves to Google Play services, never an arbitrary intent.

The code comes back through the Flutter bridge as a native-otp event on window, and the same web script fills and submits. The page does not know or care which path delivered it.

What does not work, and what tripped us

The signing hash has to be the Play one. WhatsApp one-tap matches the app by its package name and an 11-character hash of the signing certificate. With Play App Signing, the certificate on users' phones is Google's, not the upload key we sign with. We measured the hashes from the APKs that Play itself generated. A release APK installed by hand carries a different hash and quietly falls back to the copy-code button. The fallback is fine; spending an afternoon wondering why one-tap "does nothing" on a sideloaded build is not.

One-tap is ready, not live. Changing an approved WhatsApp template's button sends it back to Meta for review, and Meta limits template edits. We built the edit as a script that is a dry run by default. Until it is applied and approved, the template keeps its copy-code button, and everything above still works with it.

WebOTP needs control of the SMS text. Where the SMS is sent by a third-party phone-auth service that writes its own message, we cannot add the @domain #code line, and WebOTP stays silent. On those paths the iOS suggestion and paste still work. On our own WhatsApp path it does not apply at all.

Result

We have not measured a before-and-after drop-off rate on code screens, so we do not quote one.

Checklist

  1. autocomplete="one-time-code", inputmode="numeric" and a digits pattern on every code field.
  2. Convert Arabic-Indic and Persian digits as the user types.
  3. Accept a pasted message, not only a pasted code, and spread it over split boxes.
  4. End your SMS with @your-domain #code so WebOTP can read it.
  5. Use WhatsApp authentication templates with the copy-code button; read the clipboard on return only when the browser allows it, and ask at most once.
  6. In native apps, add one-tap / zero-tap and SMS User Consent, and verify the sender of every intent.
  7. Put it in one shared script in the layout, and add a test that fails when a code field is missing the attributes.

Need this?

Phone sign-in with WhatsApp codes that fill themselves comes built into every GeoTech product, and Kauthar AI can send those codes for your own business from an official WhatsApp number. If your sign-up loses people at the code screen, talk to GeoTech.