playwright: [BUG] page.goto: Navigation failed because page was closed! when executing test in Firefox in headed mode

Context:

  • Playwright Version: 1.23.2
  • Operating System: Windows
  • Node.js version: 12.18.3
  • Browser: firefox
  • Extra:

Config File

const config = {
    outputDir: './test-results',
    use: {
      baseURL: 'http://localhost:5500',
      browserName: 'firefox',
      headless: false,
      viewport: { width: 600, height: 800 },
      video: 'on',
      launchOptions: {
        slowMo: 500,
      },
    },
  };
  
  module.exports = config;

Test File

const { test, expect } = require('@playwright/test');

//Menu opens when clicked
test('open menu', async ({ page }) => {
  await page.goto(''); 
  await page.locator('#menuBtn').click();
  await expect(page.locator('#sideMenu')).toBeVisible();
});

Describe the bug The test succeeds when I set the browserName to either chromium or webkit in the config file, but fails when I set browserName to firefox in the config file. When the test fails, I see this error:

PS C:\dev\book\speedscore> npx playwright test

Running 1 test using 1 worker

  ✘  tests\menuVisualTests.spec.js:4:1 › open menu (2s)


  1) tests\menuVisualTests.spec.js:4:1 › open menu =================================================

    page.goto: Navigation failed because page was closed!
    =========================== logs ===========================
    navigating to "http://localhost:5500/", waiting until "load"
    ============================================================

      3 | //Menu opens when clicked
      4 | test('open menu', async ({ page }) => {
    > 5 |   await page.goto(''); 
        |              ^
      6 |   await page.locator('#menuBtn').click();
      7 |   await expect(page.locator('#sideMenu')).toBeVisible();
      8 | });

        at C:\dev\book\speedscore\tests\menuVisualTests.spec.js:5:14
        at C:\dev\book\speedscore\node_modules\@playwright\test\lib\workerRunner.js:388:15
        at TestInfoImpl._runFn (C:\dev\book\speedscore\node_modules\@playwright\test\lib\testInfo.js:166:7)
        at C:\dev\book\speedscore\node_modules\@playwright\test\lib\workerRunner.js:344:26
        at TimeoutManager.runWithTimeout (C:\dev\book\speedscore\node_modules\@playwright\test\lib\timeoutManager.js:70:7)
        at TestInfoImpl._runWithTimeout (C:\dev\book\speedscore\node_modules\@playwright\test\lib\testInfo.js:154:26)
        at WorkerRunner._runTest (C:\dev\book\speedscore\node_modules\@playwright\test\lib\workerRunner.js:326:5)
        at WorkerRunner.runTestGroup (C:\dev\book\speedscore\node_modules\@playwright\test\lib\workerRunner.js:195:11)
        at process.<anonymous> (C:\dev\book\speedscore\node_modules\@playwright\test\lib\worker.js:87:5)


  1 failed
    tests\menuVisualTests.spec.js:4:1 › open menu ==================================================

Pretty strange, huh?

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 19 (4 by maintainers)

Commits related to this issue

Most upvoted comments

I had this in the past with page.reload(). It was fixed in a new webkit release I believe. Now I have it again in the latest version of Playwright (1.32.2).

  Error: page.reload: Navigation failed because page was closed!
    =========================== logs ===========================
    waiting for navigation until "load"

Had the same issue here. My machine is a macOS Ventura and page.goto passed on Webkit and Chrome but fails on the firefox.

1) [firefox] › urls-mobile.spec.ts:13:5 › Mobile URLs validation › URL: / ────

    page.goto: Navigation failed because page was closed!
    =========================== logs ===========================
    navigating to "http://localhost:1024/", waiting until "load"
    ============================================================

      12 |   URLS.forEach(async (URL) => {
      13 |     test(`URL: ${URL}`, async ({ page }) => {
    > 14 |       await page.goto(URL);
         |                  ^
      15 |       await expect(page).not.toHaveTitle(/Page not found!/);
      16 |     });
      17 |   });

I think there is a problem with the firefox driver or something.

This is likely not going to help, however in my case a simple await fixed the problem

page.goto(`${BASE_URL}/app/p/com--demo--app/channel/23`)
await page.goto(`${BASE_URL}/app/p/com--demo--app/channel/23`)

I use BuddyWorks pipelines and getting “Navigation failed because page was closed!” on any test browser. Works perfectly fine locally, but doesn’t when I try to run simple tests in the pipeline. This is so frustrating.

I also get the same issue when running on github actions!

Test timeout of 30000ms exceeded.

    Error: page.goto: Navigation failed because page was closed!
    =========================== logs ===========================
    navigating to "http://127.0.0.1:3006/", waiting until "load"
    ============================================================

       at fixtures/portal.ts:40

      38 |
      39 | 	async login() {
    > 40 | 		await this.page.goto("/", {
         | 		                ^
      41 | 			waitUntil: "load",
      42 | 		});
      43 | 		await this.appLayout.signInButton.click();

        at Portal.login (/home/runner/work/portal/portal/tests/fixtures/portal.ts:40:[19](https://github.com/parcelLab/portal/actions/runs/5624032963/job/15239988693#step:6:20))
        at /home/runner/work/portal/portal/tests/integration/app.spec.ts:12:16
        at /home/runner/work/portal/portal/tests/integration/app.spec.ts:11:13

But I can’t reproduce this in any way on my local! It doesn’t seem to be related to a specific browser, just fails on the 1st on that is set to run the test suite on (it is using only one worker).

Tried using goto with different event listeners and some timeout, but still, no improvements

Happening in ubuntu jammy in next js 13.4. Exact same error. Any fix so far? Other browsers are fine only safari mobile it is crashing

@chundhau Could you please follow this section, but replace pw:api with pw:browser*,pw:api, and then paste the logs here? Make sure to choose a powershell or a batch version, depending on what you use.