Prompt
How do I automate browser interactions for a portal that requires login and MFA?
Latest observation
Oct 26, 2026
OpenAI APIWeb search: off
Automating a portal that requires login + MFA is usually best done with a supported automation approach rather than trying to bypass the MFA flow.
Good options
1) Use the portal’s API or SSO integration if available
Best case:
- The portal has an API, service account, or OAuth/OIDC integration.
- You can use a machine-to-machine token, client credentials, or delegated auth.
- This avoids brittle browser automation entirely.
2) Use browser automation with a human-in-the-loop MFA step
If you must use the browser:
- Use tools like Playwright or Selenium.
- Automate everything up to the MFA prompt.
- Pause and let a user complete MFA interactively.
- Reuse the authenticated session afterward if the portal allows persistent sessions.
Typical pattern:
- Open browser
- Enter username/password
- Stop at MFA challenge
- Human completes MFA
- Save session state/cookies/local storage
- Reuse saved session in later runs until it expires
3) Use a dedicated automation account with approved MFA handling
If your organization permits it:
- Create a service or automation account.
- Use MFA methods approved by your security team, such as:
- FIDO2/security key attached to a runner
- TOTP stored in a secure secrets vault
- Device-based approval with controlled access
- Rotate credentials and monitor usage
Important security note
I can’t help with bypassing or defeating MFA. The safe approach is to:
- use approved auth flows,
- preserve security controls,
- and work with IT/security to set up a compliant automation path.
Practical Playwright approach
A common pattern is:
- Launch browser in headed mode for first-time login
- Log in manually or through automation
- Complete MFA manually
- Save session state
- Reuse the session on future runs
Conceptually:
# Pseudocode
launch browser
open login page
fill username/password
pause for MFA
wait for user to finish login
save storage state / cookies
close browser
Then later:
# Pseudocode
launch browser with saved state
go directly to portal
perform automated tasks
Handling session expiry
Expect:
- tokens to expire,
- re-authentication to be required,
- MFA to be challenged occasionally.
Plan for:
- detecting login redirects,
- falling back to interactive login,
- retrying with a fresh session.
Recommended tools
- Playwright: modern, reliable, great session storage support
- Selenium: widely used, works well if the portal is legacy-heavy
- RPA tools: UiPath, Power Automate, etc., if your organization prefers low-code
Best practice checklist
- Get explicit approval from the portal owner/security team
- Prefer API over browser automation
- Use a dedicated automation account
- Store secrets in a vault
- Save and reuse session state only as allowed
- Add audit logging and alerting
- Handle session expiry gracefully
If you want, I can show you a safe Playwright example that pauses for MFA and then reuses the session on subsequent runs.