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.
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.
container:
image: mcr.microsoft.com/playwright:v1.49.0-jammy
options: --shm-size=1gbAwait every Playwright action
- Audit the failing test for un-awaited
page.*calls. - Add
awaitso the test does not finish while actions are pending. - Avoid closing contexts you still reference later.
await page.getByRole('button').click();
await expect(page).toHaveURL(/\/done/);How to prevent it
- Run Chromium with adequate
--shm-sizein containers. - Lint for missing
awaiton async Playwright calls. - Keep contexts open until every assertion that uses them completes.