OTPilot

Framework guide

Handle 2FA and OTP codes in Playwright automatically

A tiny helper for Playwright scripts and tests that log into real accounts. OTPilot keeps the TOTP seed encrypted on its side; your Playwright agent only ever receives the current code, its expiry and the next code.

Playwright · typescript
import { test } from "@playwright/test";

async function otp(account = "shopify") {
  const r = await fetch(`https://otpilot.vibiz.app/api/v1/codes/${account}`, {
    headers: { Authorization: `Bearer ${process.env.OTPILOT_KEY}` },
  });
  const data = await r.json();
  if (!r.ok) throw new Error(`${data.error.message} Fix: ${data.error.fix}`);
  // If the code is about to roll over, use the next one.
  return data.expires_in < 4 ? data.next_code : data.code;
}

test("log into Shopify", async ({ page }) => {
  // ...fill email + password...
  await page.getByLabel(/authentication code|verification code|2fa/i).fill(await otp());
  await page.keyboard.press("Enter");
});

Why not put the seed in your Playwright code?

Playwright 2FA guides by site

All 150 sites →

Try it with your own secret — no signup

Paste a TOTP secret on the home page and get a live code plus a working API call in seconds.