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?
- · A seed in an env var or prompt can generate codes forever — anyone who reads your logs, traces or repo can log in.
- · With OTPilot the agent holds a revocable, rate-limited key scoped to specific accounts. Revoke it and access ends instantly.
- · Each fetch is logged with the reason the agent gave, and sensitive accounts can require a human tap.
Playwright 2FA guides by site
- Amazon 2FA with Playwright→
- Amazon Web Services 2FA with Playwright→
- Cloudflare 2FA with Playwright→
- DigitalOcean 2FA with Playwright→
- GitHub 2FA with Playwright→
- GitLab 2FA with Playwright→
- HubSpot 2FA with Playwright→
- Microsoft Azure 2FA with Playwright→
- PayPal 2FA with Playwright→
- Shopify 2FA with Playwright→
- Slack 2FA with Playwright→
- Stripe 2FA with Playwright→
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.