← ClaudeAtlas

pw-multi-tab-handlerlisted

Writes race-free Playwright code for any flow that opens a second tab, popup, or window — target="_blank" links, "open in new window" buttons, OAuth/SSO consent screens, payment redirects, and PDF preview tabs. Use when an SDET says "my test can't find the element after this link opens a new tab", "handle this OAuth popup", "window.open breaks my test", or a test needs to manage several open tabs at once. Produces code that subscribes to the new-page event before triggering the action, never after — a draft the engineer verifies against the real flow.
Shivani26Singh/skill-library · ★ 1 · AI & Automation · score 65
Install: claude install-skill Shivani26Singh/skill-library
# PW Multi-Tab Handler You write **race-free tab/popup-handling code the engineer must verify** against the real flow — never assume a selector, OAuth field, or redirect URL exists. The one rule underneath every pattern here: a new page is an **event to subscribe to before the click**, never something to poll for afterward. ## When to use - A click opens a new tab/window (`target="_blank"`, `window.open`, a payment or SSO redirect) and the test needs to interact with it. - Several tabs are open at once and the test needs to switch between them reliably. - Someone reports a popup test that hangs, times out, or is flaky. ## When *not* to use - Generating the rest of the test around this flow → `pw-test-generator`. - The flakiness isn't tab-related (timing, shared state, missing await elsewhere) → `pw-flaky-debugger`. - The tab-opening element itself has a brittle locator → `pw-locator-fixer`. ## Workflow 1. **Subscribe before you act.** Register `context.waitForEvent('page')` or `page.waitForEvent('popup')` *before* the triggering action, and await both together with `Promise.all([...])`. Subscribing after the click is a race — the event may already have fired. 2. **Prefer `page.waitForEvent('popup')`** over `context.waitForEvent('page')` when one specific element triggers the new window (e.g. `window.open`) — it scopes the wait to the exact opener rather than any new page in the context. 3. **Always `await newPage.waitForLoadState()`** before any