Skip to content
Playwright · error message

Playwright: page.goto: net::ERR_CONNECTION_REFUSED

RetryableNavigation & network

Last verified

The exact message
Error: page.goto: net::ERR_CONNECTION_REFUSED at http://localhost:3000/ Call log: - navigating to "http://localhost:3000/", waiting until "load"

What it means

The hostname resolved, but nothing accepted a TCP connection on that address and port. The operating system answered with a refusal, so the browser reported net::ERR_CONNECTION_REFUSED and Playwright threw from page.goto. In Firefox the equivalent is NS_ERROR_CONNECTION_REFUSED.

In test suites this almost always means the application under test is not running yet, or is listening somewhere other than where the browser is looking. A classic case is localhost inside a Docker container: it refers to the container itself, not the host where your dev server runs. Another is IPv6: Node.js may bind to ::1 while the browser connects to 127.0.0.1, or the reverse.

What is not wrong: DNS and the URL's hostname. Unlike a timeout, a refusal is instant and definite.

What it looks like

// playwright.config.ts
import { defineConfig } from '@playwright/test';

export default defineConfig({
  webServer: {
    command: 'npm run start',
    url: 'http://127.0.0.1:3000',
    reuseExistingServer: !process.env.CI,
    timeout: 120_000,
  },
  use: { baseURL: 'http://127.0.0.1:3000' },
});

Why it happens

  • The web server has not finished starting when the first test navigates.
  • The server crashed or exited, or is listening on a different port.
  • The browser runs in a container where localhost is the container, not the host machine.
  • The server binds to 127.0.0.1 or ::1 only, and the browser connects over the other address family.
  • A firewall or security group rejects the port.

How to fix it

  1. Confirm the server is up from the same environment: curl -v http://localhost:3000/.
  2. In Playwright Test, let the runner start and wait for the server with the webServer option and its url setting.
  3. Inside Docker, target the host by service name or host.docker.internal, and make the server listen on 0.0.0.0.
  4. Try 127.0.0.1 instead of localhost (or the reverse) to rule out IPv4/IPv6 mismatch.
  5. For external targets, retry once after a short delay; refusals that persist mean the service is down.

How to stop it recurring

Never rely on a fixed sleep for server startup; use the webServer option or a readiness probe that polls the URL. Use explicit 127.0.0.1 in both the server bind and the base URL to avoid address-family surprises. In containerized setups, document which hostname the browser should use and set it through one environment variable.

Official documentation: playwright.dev/docs/test-webserver. See all Playwright error messages.

Related errors

Definitions

Quick answers

What does "page.goto: net::ERR_CONNECTION_REFUSED" mean in Playwright?

The hostname resolved, but nothing accepted a TCP connection on that address and port. The operating system answered with a refusal, so the browser reported net::ERR_CONNECTION_REFUSED and Playwright threw from page.goto . In Firefox the equivalent is NS_ERROR_CONNECTION_REFUSED .

How do I fix "page.goto: net::ERR_CONNECTION_REFUSED"?

1. Confirm the server is up from the same environment: curl -v http://localhost:3000/. 2. In Playwright Test, let the runner start and wait for the server with the webServer option and its url setting. 3. Inside Docker, target the host by service name or host.docker.internal, and make the server listen on 0.0.0.0. 4. Try 127.0.0.1 instead of localhost (or the reverse) to rule out IPv4/IPv6 mismatch. 5. For external targets, retry once after a short delay; refusals that persist mean the service is down.

Run browser automation you can watch and take over

Autonoly runs each job in a real cloud Chromium browser driven by Playwright. Timeouts and detached elements still happen; the difference is that you can watch the run live, see the step that failed, and take control of the browser to finish it.

Also see Live browser control.