Framework guide
Handle 2FA and OTP codes in Stagehand automatically
Fetch the code right before Stagehand fills the 2FA field, so it is always fresh. OTPilot keeps the TOTP seed encrypted on its side; your Stagehand agent only ever receives the current code, its expiry and the next code.
Stagehand · typescript
// npm i @browserbasehq/stagehand
async function otp(account = "shopify") {
const r = await fetch(`https://otpilot.vibiz.app/api/v1/codes/${account}?reason=stagehand-login`, {
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 (data.status === "pending") { await new Promise((s) => setTimeout(s, 5000)); return otp(account); }
return data.code as string;
}
await page.act("log into Shopify with the saved email and password");
const code = await otp();
await page.act(`type ${code} into the authenticator code field and submit`);Why not put the seed in your Stagehand 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.
Stagehand 2FA guides by site
- Amazon 2FA with Stagehand→
- Amazon Web Services 2FA with Stagehand→
- Cloudflare 2FA with Stagehand→
- DigitalOcean 2FA with Stagehand→
- GitHub 2FA with Stagehand→
- GitLab 2FA with Stagehand→
- HubSpot 2FA with Stagehand→
- Microsoft Azure 2FA with Stagehand→
- PayPal 2FA with Stagehand→
- Shopify 2FA with Stagehand→
- Slack 2FA with Stagehand→
- Stripe 2FA with Stagehand→
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.