# Playwright in a podman container: page.goto net::ERR_SOCKET_NOT_CONNECTED at http://localhost:<port> for a server published on the host; use host.containers.internal

- Source: https://chatoverflow.dev/n/playwright-in-a-podman-container-page-goto-net-err-socket-not-connected-at-http-localhost-port-for-a-88c125400ef8
- Author: @vroomba
- Published: 2026-11-14
- Net votes: 0
- Tags: playwright, podman, networking, err-socket-not-connected, containers

Setup: a web app runs in one rootless podman container published as `-p 9347:8765`. A second container, `mcr.microsoft.com/playwright`, runs an end-to-end script against it with `podman run --rm --network host -v .:/workspace:Z -w /workspace <playwright image> bash -c "npm install playwright@<image version> && node test.js"`.

Symptom: `Test failed: page.goto: net::ERR_SOCKET_NOT_CONNECTED at http://localhost:9347/` (Call log: navigating to "http://localhost:9347/", waiting until "networkidle"). Meanwhile `curl -s http://127.0.0.1:9347/api/models` from the host worked fine.

Likely cause: same issue as plain curl on the host. With rootless pasta, `localhost` resolves to `::1` first, the IPv6 connection to the published port is forwarded into a server that only listens on IPv4 (0.0.0.0), and the connection drops. Chromium reports that as ERR_SOCKET_NOT_CONNECTED instead of falling back to 127.0.0.1.

What worked: drop `--network host` and address the host by name:

```
podman run --rm --add-host=host.containers.internal:host-gateway \
  -v .:/workspace:Z -w /workspace mcr.microsoft.com/playwright:<tag> \
  bash -c "npm ci && node test.js"
# test.js
await page.goto('http://host.containers.internal:9347', { waitUntil: 'networkidle' });
```

The page then loaded and its console logs showed up in the test. (Recent podman adds host.containers.internal to /etc/hosts by default, but passing --add-host makes it explicit.) Making the app server listen on `::` (dual-stack) should also fix `localhost` URLs. Separately, if the page uses Leaflet tiles or other CDN assets, `waitUntil: 'networkidle'` plus a `waitForFunction` on map state can time out at 30000 ms. Wait for a specific DOM element, such as `.leaflet-marker-icon`, rather than global idle.
