Playwright Multi-Tab & Window Handling
БесплатноБез исполняемых скриптовНе проверенTeaches the agent to handle popups, new tabs, and multiple browser windows in Playwright using waitForEvent('page'), context pages, and reliable tab switching…
от PramodDutta★ 253 звезды на GitHubОб этом скилле
Playwright Multi-Tab & Window Handling
This skill makes the agent write correct, race-free code for any flow that opens a second tab or popup: target="_blank" links, "Open in new window" buttons, OAuth/SSO consent screens, payment redirects, and PDF preview tabs. The central rule is that a new page is an event you must subscribe to before the click, never a thing you poll for afterward.
Use this skill whenever a test clicks something and a new tab/window appears, or whenever the agent sees page.waitForTimeout being used to "wait for the popup."
Core Principles
- Subscribe before you click. Register
context.waitForEvent('page')(orpage.waitForEvent('popup')) before the action that triggers the popup, thenawaitboth together. Subscribing after the click is a race. - A tab belongs to a
BrowserContext, not aPage. All tabs in one context share cookies/storage.context.pages()is the live list of open tabs. - Always
await newPage.waitForLoadState()before asserting — the page object resolves the moment the tab exists, not when it has loaded. - Switch by holding a reference, never by index. Index order is not guaranteed across browsers. Capture the returned
Pageobject. - Close popups you opened. Leaked tabs slow the suite and can hold modal focus. Close them or rely on context teardown.
- Cross-origin popups are fine within a context. OAuth on a different domain still arrives as a
pageevent; you do not need a new context.
Workflow / Patterns
Pattern 1 — Capture a popup from a target="_blank" link
The canonical, race-free shape uses Promise.all: start listening, then click, in one expression.
import { test, expect } from '@playwright/test';
test('opens docs in a new tab', async ({ context, page }) => {
await page.goto('https://example.com/app');
// Subscribe BEFORE the click, await both together.
const [newPage] = await Promise.all([
context.waitForEvent('page'),
page.getByRole('link', { name: 'Open docs' }).click(),
]);
// The page object exists, but the tab may still be loading.
await newPage.waitForLoadState('domcontentloaded');
await expect(newPage).toHaveURL(/\/docs/);
await expect(newPage.getByRole('heading', { name: 'Documentation' })).toBeVisible();
await newPage.close();
// Original tab is still fully usable.
await expect(page.getByRole('button', { name: 'Back to app' })).toBeVisible();
});
Pattern 2 — page.waitForEvent('popup') for window.open
When the element calls window.open(), the popup event on the opener page is the most precise listener — it ties the new page to the exact opener.
test('handles a window.open popup', async ({ page }) => {
await page.goto('https://example.com/share');
const popupPromise = page.waitForEvent('popup');
await page.getByRole('button', { name: 'Share to LinkedIn' }).click();
const popup = await popupPromise;
await popup.waitForLoadState();
await expect(popup).toHaveURL(/linkedin\.com/);
await popup.close();
});
Pattern 3 — Multi-tab OAuth / SSO consent flow
The provider page opens in a popup, you authenticate there, the popup closes itself, and the original tab becomes authenticated. Wait for the popup to close before asserting on the main page.
test('logs in via Google OAuth popup', async ({ page }) => {
await page.goto('https://example.com/login');
const popupPromise = page.waitForEvent('popup');
await page.getByRole('button', { name: 'Continue with Google' }).click();
const oauth = await popupPromise;
// Drive the provider's consent screen inside the popup.
await oauth.waitForLoadState('domcontentloaded');
await oauth.getByLabel('Email').fill(process.env.OAUTH_EMAIL!);
await oauth.getByRole('button', { name: 'Next' }).click();
await oauth.getByLabel('Password').fill(process.env.OAUTH_PASSWORD!);
await oauth.getByRole('button', { name: 'Sign in' }).click();
await oauth.getByRole('button', { name: 'Allow' }).click();
// The provider closes its own window; wait for that, then assert on main page.
await oauth.waitForEvent('close');
await expect(page.getByText('Signed in as')).toBeVisible({ timeout: 15_000 });
});
Pattern 4 — Several tabs open at once, switch deterministically
Hold each Page in a variable. Never rely on context.pages()[1] order.
test('manages three tabs by reference', async ({ context, page }) => {
await page.goto('https://example.com/reports');
const [reportA] = await Promise.all([
context.waitForEvent('page'),
page.getByRole('link', { name: 'Report A' }).click(),
]);
const [reportB] = await Promise.all([
context.waitForEvent('page'),
page.getByRole('link', { name: 'Report B' }).click(),
]);
await reportA.waitForLoadState();
await reportB.waitForLoadState();
// Bring a specific tab to the foreground (affects screenshots / focus).
await reportB.bringToFr
Установить Playwright Multi-Tab & Window Handling в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл Playwright Multi-Tab & Window Handling?
Teaches the agent to handle popups, new tabs, and multiple browser windows in Playwright using waitForEvent('page'), context pages, and reliable tab switching for OAuth and target=_blank links.
Как установить скилл Playwright Multi-Tab & Window Handling?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл Playwright Multi-Tab & Window Handling запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic