[BUG] browser.newContext: Target page, context or browser
See original GitHub issueContext:
- Playwright Version: 1.20.1
- Operating System: any
- Node.js version: 14.6
- Browser: firefox
Error in debug mode
✘ [Desktop Firefox] › PublicSearch/LandingPage.test.ts:56:5 › Landing page Test Suite › User can search for (1ms)
pw:browser [pid=30113] <process did exit: exitCode=0, signal=null> +8ms
pw:browser ffmpeg onkill exitCode=0 signal=null +0ms
pw:browser [pid=30113] starting temporary directories cleanup +0ms
pw:browser [pid=30113] finished temporary directories cleanup +0ms
pw:browser [pid=30113] <gracefully close end> +0ms
1) [Desktop Firefox] › PublicSearch/LandingPage.test.ts:56:5 › Landing page Test Suite › User can search for a city using EN/DE/IT lang while selected lang is FR
browser.newContext: Target page, context or browser has been closed
Code Snippet
test.beforeEach(async ({ page, landingPage }) => {
await page.goto(path.en.landingPage, { waitUntil: "load", timeout: 30000 })
await landingPage.waitForText('Log in')
});
test('User can search for a city using EN/DE/IT lang while selected lang is FR', async ({ page, landingPage }) => {
await page.goto(path.fr.landingPage, { waitUntil: "load" })
await landingPage.searchForCity('c')
await expect.soft(page.locator('text=c >> nth=0')).toBeVisible();
await landingPage.searchForCity('c')
await expect.soft(page.locator('text=zurich >> nth=0')).toBeVisible();
await landingPage.searchForCity('c')
await expect.soft(page.locator('text=zurich >> nth=0')).toBeVisible();
});
Describe the bug
I have noticed that I’m getting the following error so often browser.newContext: Target page, context, or browser
when a test is running against firefox, it happens randomly with different tests, I failed to find certain steps to reproduce.
but it’s obviously happening when you run multiple tests with firefox. especially if the tests are executed in a very short time, this is my guess, all failure was happening on the hook

Issue Analytics
- State:
- Created a year ago
- Comments:19 (8 by maintainers)
Top Results From Across the Web
Playwright error (Target closed) after navigation
You can need to wait for the navigation, not the press action. const context = await browser.newContext(); const page = await context.
Read more >playwright._impl._api_types.error: execution context was ...
I came into this issue today, and found that this problem occurs in this case: I was use page object loading a url...
Read more >Multi-page scenarios | Playwright 中文文档
The page event on browser contexts can be used to get new pages that are created in the context. This can be used...
Read more >Browser - MarketSquare
The Open Browser keyword opens a new browser, a new context and a new page. This keyword is useful for quick experiments or...
Read more >BrowserContext (Playwright - Main Library 1.12.1 API)
open call, the popup will belong to the parent page's browser context. Playwright allows creation of "incognito" browser contexts with browser.newContext() ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I have exactly the same issue. this error line shows randomly only for firefox when I ran tests with --headed option.
browser.newContext: Target page, context or browser has been closed
And when I see the test report, there is read ‘x’ next to the ‘Before Hooks’ while ‘After Hooks’ has green checkmark.
it happened to this simple test (and another simple test, which are all after other simple tests), which uses a few page objects, and I don’t handle browser or context at all. I guess, this is truly a bug
@mxschmitt could we reopen this ticket again, i might be able to provide a reproducible code.