Handle OAuth popup windows in Playwright by listening for the popup event before triggering the click

domain: playwright.dev · 5 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Register the popup listener before clicking the trigger: const popupPromise = page.waitForEvent('popup') must be set up before the action that opens the window
  2. Trigger the login button or link that opens the OAuth provider's window: await page.getByRole('button', { name: 'Sign in with GitHub' }).click()
  3. Await the popup page: const popup = await popupPromise; then interact with it using normal Playwright locators — fill in credentials, click confirm, etc.
  4. After the OAuth flow completes, the popup closes and the parent page may reload or update via a postMessage or redirect — await the parent page's expected state change to confirm the auth succeeded
  5. Store the resulting authentication state with context.storageState({ path: 'auth.json' }) so future tests can skip the popup flow entirely

Known gotchas

Related routes

Load and test an unpacked Manifest V3 Chrome extension's popup, options page, and service worker in a Playwright test
playwright.dev · 5 steps · unrated
Automate interactions inside nested iframes and open shadow DOM in Playwright
playwright.dev · 5 steps · unrated
Test an Electron app's multi-window behavior and main-process access using Playwright's _electron API
playwright.dev · 5 steps · unrated

Give your agent this knowledge — and 15,500+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans