Skip to content

Linux + iPhone Continuity / iMessage / SMS

handle walmart OTP

Zack Bartelca70af73d9b2
diff --git a/extension/src/content/autofill.js b/extension/src/content/autofill.js
index 0b58ca2..ce1d1f1 100644
--- a/extension/src/content/autofill.js
+++ b/extension/src/content/autofill.js
@@ -40,13 +40,39 @@ export function scoreInput(input) {
}
export function detectSplitOtp(doc) {
- const singles = [...doc.querySelectorAll('input[maxlength="1"]')]
+ const inputs = [...doc.querySelectorAll('input')]
.filter(i => i.type === 'text' || i.type === 'tel' || i.type === 'number' || !i.type);
- // Check if they're siblings/adjacent — likely a split OTP
+ // Strategy 1: exact maxlength=1 (standard split OTP)
+ const singles = inputs.filter(i => i.maxLength === 1);
if (singles.length >= 4 && singles.length <= 8) {
- return singles; // fill character by character
+ return singles;
}
+
+ // Strategy 2: Clustered inputs under same parent with OTP keywords (e.g. Walmart)
+ const parentMap = new Map();
+ inputs.forEach(input => {
+ const p = input.parentElement;
+ if (p) {
+ if (!parentMap.has(p)) parentMap.set(p, []);
+ parentMap.get(p).push(input);
+ }
+ });
+
+ for (const group of parentMap.values()) {
+ if (group.length >= 4 && group.length <= 8) {
+ const otpScore = group.reduce((acc, input) => {
+ const attrs = [input.id, input.name, input.className, input.getAttribute('aria-label')]
+ .join(' ').toLowerCase();
+ if (/\botp\b|\bcode\b|verif|digit/.test(attrs)) return acc + 1;
+ return acc;
+ }, 0);
+
+ // If at least half the inputs in the group look like OTP inputs
+ if (otpScore >= group.length / 2) return group;
+ }
+ }
+
return null;
}
diff --git a/extension/test/autofill.test.js b/extension/test/autofill.test.js
index d199bf2..636d4a7 100644
--- a/extension/test/autofill.test.js
+++ b/extension/test/autofill.test.js
@@ -52,6 +52,12 @@ describe('OTP input detection', () => {
const inputs = findOtpInputs(doc);
expect(inputs.length).toBe(1);
});
+
+ it('detects walmart split-style inputs with maxlength=6', () => {
+ const doc = loadFixture('walmart.html');
+ const inputs = detectSplitOtp(doc);
+ expect(inputs).toHaveLength(6);
+ });
});
describe('scoreInput', () => {
@@ -96,6 +102,22 @@ describe('OTP autofill insertion', () => {
expect(inputs[1].value).toBe('2');
expect(inputs[5].value).toBe('6');
});
+
+ it('fills walmart split-style inputs character by character', () => {
+ const doc = loadFixture('walmart.html');
+ const inputs = detectSplitOtp(doc);
+
+ const otp = '654321';
+ for (let i = 0; i < otp.length; i++) {
+ inputs[i].value = otp[i];
+ inputs[i].dispatchEvent(new doc.defaultView.Event('input', { bubbles: true }));
+ inputs[i].dispatchEvent(new doc.defaultView.Event('change', { bubbles: true }));
+ }
+
+ expect(inputs[0].value).toBe('6');
+ expect(inputs[1].value).toBe('5');
+ expect(inputs[5].value).toBe('1');
+ });
});
describe('single OTP filling', () => {
diff --git a/extension/test/fixtures/walmart.html b/extension/test/fixtures/walmart.html
new file mode 100644
index 0000000..3bcdeb1
--- /dev/null
+++ b/extension/test/fixtures/walmart.html
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<html>
+<body>
+ <form id="verify-phone-otp-form" novalidate="">
+ <div class="mt3 tl" data-testid="verifyotpform-description">
+ <span class="dark-gray" data-qm-mask="true">
+ <span>Please enter the 6-digit verification code we sent to</span>
+ <strong>[email protected] </strong>
+ </span>
+ </div>
+ <fieldset class="bw0 pl4 pr4 mt3 pv0" name="verificationCodeSection" aria-label="Please enter the 6-digit verification code">
+ <div class="flex justify-between w-100" style="column-gap: 10px;">
+ <input id="input-verificationCode" name="verificationCode-0" type="text" inputmode="numeric" pattern="[0-9]*" autocomplete="off" aria-label="digit 1 . On entering code in the input fields, focus will automatically move on to the next input fields." maxlength="6" class="otp-input w-100 br3 pa0 tc f2 b lh-solid ba" style="height: 52px; border-color: rgb(144, 145, 150);" value="">
+ <input id="input-verificationCode-1" name="verificationCode-1" type="text" inputmode="numeric" pattern="[0-9]*" autocomplete="off" aria-label="digit 2 " maxlength="6" class="otp-input w-100 br3 pa0 tc f2 b lh-solid ba" style="height: 52px; border-color: rgb(144, 145, 150);" value="">
+ <input id="input-verificationCode-2" name="verificationCode-2" type="text" inputmode="numeric" pattern="[0-9]*" autocomplete="off" aria-label="digit 3 " maxlength="6" class="otp-input w-100 br3 pa0 tc f2 b lh-solid ba" style="height: 52px; border-color: rgb(144, 145, 150);" value="">
+ <input id="input-verificationCode-3" name="verificationCode-3" type="text" inputmode="numeric" pattern="[0-9]*" autocomplete="off" aria-label="digit 4 " maxlength="6" class="otp-input w-100 br3 pa0 tc f2 b lh-solid ba" style="height: 52px; border-color: rgb(144, 145, 150);" value="">
+ <input id="input-verificationCode-4" name="verificationCode-4" type="text" inputmode="numeric" pattern="[0-9]*" autocomplete="off" aria-label="digit 5 " maxlength="6" class="otp-input w-100 br3 pa0 tc f2 b lh-solid ba" style="height: 52px; border-color: rgb(144, 145, 150);" value="">
+ <input id="input-verificationCode-5" name="verificationCode-5" type="text" inputmode="numeric" pattern="[0-9]*" autocomplete="off" aria-label="digit 6 " maxlength="6" class="otp-input w-100 br3 pa0 tc f2 b lh-solid ba" style="height: 52px; border-color: rgb(144, 145, 150);" value="">
+ </div>
+ <div class="f5 flex mt2 mb3 items-center justify-center ">
+ <span class="dark-gray f6 tc">Didn't receive it?</span>
+ <a link-identifier="getAnotherCode" class="dark-gray f6 pl2 underline" id="resend-button" aria-label="Didn't receive it? Get another code" role="button" href="#">Get another code</a>
+ </div>
+ </fieldset>
+ <div class="pb3 pl4">
+ <label class="ld_AK ld_AL" for="keep-signed-in">
+ <input id="keep-signed-in" type="checkbox" checked="">
+ <span>Keep me signed in</span>
+ </label>
+ </div>
+ <button class="Button_button__s6lnv Button_primary___r9Bd Button_isFullWidth__8bg_i Button_medium__QLNmo pa4" type="submit" form="verify-phone-otp-form">Sign in</button>
+ </form>
+</body>
+</html>