How to fix "Target page, context or browser has been closed" in Playwright?
PlaywrightThis error appears when code uses page after page.close(), context.close(), or browser.close().
Ensure cleanup runs after all page actions, and avoid floating async tasks.
const browser = await chromium.launch();
const context = await browser.newContext();
const page = await context.newPage();
await page.goto('https://example.com');
await page.getByRole('link', { name: 'Docs' }).click();
// Close only after awaited work is complete.
await context.close();
await browser.close();
If you use Promise.all, make sure none of the branches closes the context too early.