← Back to Discord Forum

Error: [...] Target page, context or browser has been closed

I'm having issues where tests that passed locally without issues are now erroring in Github Actions CI with the error stated in the title (see attached photo for example). These tests failed on a variety of actions (fill, click) and assertions (toContainText). I've seen similar issues on github that were closed without any resolution (https://github.com/microsoft/playwright/issues/13090). There was nothing of note from reviewing these erroring tests in the trace viewer. ###System Info

  • Playwright Version: [v1.35.1]
  • Operating System: [macOS 12.6.2, etc.]
  • Browser: [WebKit]

So far, I've tried using different locators and increasing timeouts in the relevant tests. I've also tried to use a docker image instead of installing the browsers in the Github Actions workflow.


This thread is trying to answer question "How can I resolve the 'Target page, context or browser has been closed' error in Github Actions CI?"

5 replies
# playwright.yml
name: Playwright Tests
on: [push]
    timeout-minutes: 20
    runs-on: ubuntu-latest
    # container:
    #   image: mcr.microsoft.com/playwright:v1.35.1-jammy
      fail-fast: false
        project: [chromium, webkit]
        shardIndex: [1, 2, 3, 4]
        shardTotal: [4]
      - uses: actions/checkout@v3
          fetch-depth: 1
      - uses: actions/setup-node@v3
          node-version: "16"
          cache: "yarn"
      - name: Install dependencies
        run: yarn --frozen-lockfile
      - name: Install Playwright Browsers
        run: npx playwright install --with-deps
      - name: Run Playwright tests
        run: yarn playwright test --project=${{ matrix.project }} --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }}
      - uses: actions/upload-artifact@v3
        if: always()
          name: playwright-report-${{ matrix.project }}-${{ matrix.shardIndex }}-${{ matrix.shardTotal }}
          path: playwright-report/
          retention-days: 5
// playwright.config.js
// @ts-check
const { defineConfig, devices } = require("@playwright/test");

 * Read environment variables from file.
 * https://github.com/motdotla/dotenv
// require('dotenv').config();

 * @see https://playwright.dev/docs/test-configuration
module.exports = defineConfig({
  testDir: "./playwright/tests",
  /* Run tests in files in parallel */
  fullyParallel: true,
  /* Fail the build on CI if you accidentally left test.only in the source code. */
  forbidOnly: !!process.env.CI,
  /* Retry on CI only */
  retries: process.env.CI ? 2 : 0,
  /* Opt out of parallel tests on CI. */
  workers: process.env.CI ? 1 : undefined,
  /* Reporter to use. See https://playwright.dev/docs/test-reporters */
  reporter: process.env.CI
    ? [["github"], ["html"], ["json", { outputFile: "results.json" }]]
    : [["html"], ["list"]],
  /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
  use: {
    /* Base URL to use in actions like `await page.goto('/')`. */
    baseURL: "http://localhost:8080",

    /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
    trace: "on-first-retry",

  /* Configure projects for major browsers */
  projects: [
      name: "chromium",
      use: { ...devices["Desktop Chrome"] },

      name: "firefox",
      use: { ...devices["Desktop Firefox"] },

      name: "webkit",
      use: { ...devices["Desktop Safari"] },

  /* Run your local dev server before starting the tests */
  webServer: {
    command: "yarn dev",
    url: "http://localhost:8080",
    timeout: 360 * 1000,
    reuseExistingServer: !process.env.CI,

Has anyone actually got playwright to run in CI for non-trivial projects out of the box aka according to the documentation without breaking issues?

also attempted to downgrade to Playwright v1.34.3. Firefox tests now pass in CI, but still running into target closed errors testing in webkit project. Comparing the passing tests in local testing vs the trace of failed tests in CI, the errors seem occur where actions or assertions just stop working and timeout (page is not closed, element is visible, enabled, etc.

https://github.com/microsoft/playwright/issues/23259 seem like this is a known issue that might be resolved with v1.37.0


Sure, let's dive into how you can troubleshoot the "Target page, context or browser has been closed" error in GitHub Actions CI with @playwright/test.

First, ensure you've initialized a git repository using git init. This is crucial for pushing your code to GitHub.

git init

Next, head over to the Actions tab on your GitHub repository. Here, you'll see the status of your workflows.

Find the workflow run that's causing trouble and click on it. You'll see a detailed list of actions that GitHub performed during that run.

Look for the "Run Playwright tests" action. Click on it to get more information about the error messages, expected results, received results, and call log.

For a more detailed report, download the HTML report by clicking on "playwright-report" in the Artifacts section.

Extract the downloaded zip file into a folder where Playwright is installed.

Now, open your command line interface (CLI), navigate to the directory where you extracted the report and run the following command:

npx playwright show-report <your-extracted-folder>

This command will serve up the report locally, allowing you to view it in your browser.

By following these steps, you'll be able to identify why your tests are failing and fix any issues related to prematurely closing target pages, contexts or browsers in GitHub Actions CI.

For more insights on handling flaky tests in Playwright, check out this blog post.

Related Discord Threads

AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.