Skip to content
Latchkey

Playwright "Target page, context or browser has been closed" in CI

Playwright tried to use a page, context, or browser that had already closed. In CI this comes from a browser crash (often out of /dev/shm space), an unawaited async action continuing after the test ended, or closing a context too early.

What this error means

A test fails with "page.click: Target page, context or browser has been closed" or the same message on another action, sometimes with browser crash logs just above.

playwright
Error: locator.click: Target page, context or browser has been closed
Browser logs:
  [pid=1234] <process did exit: exitCode=null, signal=SIGTRAP>

Common causes

The browser crashed mid-test

A renderer crash, frequently from a small /dev/shm in a container, closes the target so the next action has nothing to act on.

An unawaited promise outlives the test

A missing await lets an action resolve after the test (and its context) closed, so it hits a closed target.

How to fix it

Give the browser more shared memory

Mount a larger /dev/shm or disable its use so Chromium does not crash under memory pressure in a container.

.github/workflows/ci.yml
container:
  image: mcr.microsoft.com/playwright:v1.49.0-jammy
  options: --shm-size=1gb

Await every Playwright action

  1. Audit the failing test for un-awaited page.* calls.
  2. Add await so the test does not finish while actions are pending.
  3. Avoid closing contexts you still reference later.
tests/checkout.spec.ts
await page.getByRole('button').click();
await expect(page).toHaveURL(/\/done/);

How to prevent it

  • Run Chromium with adequate --shm-size in containers.
  • Lint for missing await on async Playwright calls.
  • Keep contexts open until every assertion that uses them completes.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →