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.
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
- Configure a
webServerblock with the start command and URL. - Playwright polls that URL and waits until it responds before tests run.
- Set
reuseExistingServer: !process.env.CIso CI always starts fresh.
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.
use: { baseURL: 'http://localhost:3000' },How to prevent it
- Always drive the app through Playwright's
webServerso readiness is enforced. - Match
baseURLto the exact host and port the app binds. - Give
webServer.timeoutenough headroom for a cold start in CI.