Skip to content
Latchkey

Playwright "net::ERR_CONNECTION_REFUSED" at page.goto in CI

Chromium tried to open the URL but nothing was listening on that host and port. In CI this almost always means the dev server defined in webServer had not finished booting, or the test used the wrong port.

What this error means

Navigation fails with "page.goto: net::ERR_CONNECTION_REFUSED at http://localhost:3000/". The same test passes locally where the server is already running.

playwright
Error: page.goto: net::ERR_CONNECTION_REFUSED at http://localhost:3000/
  navigating to "http://localhost:3000/", waiting until "load"

Common causes

The webServer was not ready before tests started

Playwright launched the server but began navigating before it bound the port, so the first connections are refused.

A port or host mismatch between baseURL and the server

The app listens on a different port (or only on 127.0.0.1 vs 0.0.0.0) than the baseURL/url Playwright probes.

How to fix it

Let Playwright manage and wait for the server

  1. Configure a webServer block with the start command and URL.
  2. Playwright polls that URL and waits until it responds before tests run.
  3. Set reuseExistingServer: !process.env.CI so CI always starts fresh.
playwright.config.ts
webServer: {
  command: 'npm run start',
  url: 'http://localhost:3000',
  reuseExistingServer: !process.env.CI,
  timeout: 120_000,
},

Align baseURL with the server bind address

Make sure the app binds the same port and host Playwright navigates to; bind 0.0.0.0 inside containers.

playwright.config.ts
use: { baseURL: 'http://localhost:3000' },

How to prevent it

  • Always drive the app through Playwright's webServer so readiness is enforced.
  • Match baseURL to the exact host and port the app binds.
  • Give webServer.timeout enough headroom for a cold start in CI.

Frequently asked questions

What causes ""net::ERR_CONNECTION_REFUSED""?
Playwright launched the server but began navigating before it bound the port, so the first connections are refused.
How do I fix "net::ERR_CONNECTION_REFUSED"?
Let Playwright manage and wait for the server

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card