Skip to content
QA Knowledge Hub

Playwright target closed

Updated 2026-11-13 · 2 min read

An action used a page after its browsing target had ended. Reproduced examples distinguish premature cleanup from normal work on a live context.

The reproduced message

Captured with Playwright 1.65.0, after explicitly closing a page:

locator.click: Target page, context or browser has been closed

The action cannot use its browsing target anymore. This is a lifecycle failure, so a more precise button locator will not fix it.

1. Cleanup runs before the action

Search for page.close(), context.close() and browser.close(), including cleanup hooks and helper methods. This deliberate failure was reproduced with an open page:

await page.setContent('<button>Pay</button>');
await page.close();
await page.getByRole('button', { name: 'Pay', exact: true }).click();

Use the page while its context is still alive. This replacement page sequence was run successfully with an open browser:

const context = await browser.newContext();
try {
  const checkout = await context.newPage();
  await checkout.setContent('<button>Pay</button>');
  await checkout.getByRole('button', { name: 'Pay', exact: true }).click();
} finally {
  await context.close();
}

2. An async helper returns too early

A missing await, or forEach(async ...), can leave actions running after a test has ended and fixture teardown has closed the page. Return or await the action promise. This sequential fixture was run:

await page.setContent('<button>Confirm</button><button>Done</button>');
async function finishCheckout(page) {
  for (const name of ['Confirm', 'Done']) {
    await page.getByRole('button', { name, exact: true }).click();
  }
}
await finishCheckout(page);

Also inspect the earlier error: a test timeout may start cleanup while a later action is still pending. Fixing only the final closed-target message misses that cause.

3. The app closes a popup, or the browser exits

If a payment popup closes by design, continue with the parent checkout page rather than reusing the popup object. If no test code closed anything, inspect browser process logs, crash evidence and CI resource limits. Do not claim a memory problem without evidence, and do not add browser flags at random.

Prevention and interview answer

Let Playwright Test own its page fixture, await helper calls, and keep test-specific contexts out of shared global state. “I find who ended the target's lifetime, then move the action before cleanup or use the surviving parent page.”

A living page with a missing control instead produces a locator timeout. Selenium's context equivalent is covered in window and frame errors.

Quick answers

Can a closed Page object be reopened?

No. Create or capture the intended live page and use that object.

Does this message prove Chromium crashed?

No. Explicit close calls and fixture teardown can produce the same message.

Sources

Want a project you can show in interviews?

The portfolio project kit walks you through testing a deliberately buggy app with Selenium or Playwright and API tests, then explaining it. The app itself is free.