pw-multi-tab-handlerlisted
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