Fix the upload step, not the trace. Playwright writes traces to local disk - that part is working, because the error happens when CI tries to ship the file somewhere (artifact storage, a trace viewer service, an S3-compatible bucket). ECONNREFUSED means the upload target refused the connection: wrong hostname or port in the upload config, no network egress from the runner to that host, or credentials the target rejects at connect time. Check the upload step's config against the storage docs, verify the runner can reach the host, and retry the upload in isolation. If the upload service is flaky, make trace upload best-effort so a failed upload does not fail the build - the test results matter more than the trace files.

```text
playwright trace fails with "ECONNREFUSED" uploading to CI artifacts: how to fix
```

## Steps
1. Confirm the trace exists locally: check the CI workspace for the trace zip. If the file is there, Playwright did its job and only the upload step is broken.
   Expected: the trace file is present on the runner - the failure is purely in the upload.

2. Read the upload step's config: hostname, port, bucket or artifact name, and credentials source. Compare each against the storage provider's docs - a wrong port is the classic ECONNREFUSED cause.
   Expected: every upload parameter is verified against the docs, especially host and port.

3. Test connectivity from the runner: a simple connection check to the upload host and port from a CI debug step tells you whether egress is blocked or the host is wrong.
   Expected: you know whether the runner can reach the host at all.

4. Retry the upload step alone (most CI providers let you re-run a single failed step). If it succeeds on retry, the service is flaky - add retries to the upload step.
   Expected: an isolated retry result: consistent failure means config, intermittent means flakiness.

5. Make trace upload non-blocking: configure the pipeline so a failed upload warns instead of failing the build. Traces are debugging aids; they should never turn a green test run red.
   Expected: a failed upload produces a warning and the build result follows the tests, not the upload.

## Use this when

- ECONNREFUSED when uploading Playwright traces to CI artifact storage
- trace files exist on the runner but never reach storage
- you need to separate trace-recording problems from upload problems

## Not for this skill when

- traces that fail to record or open locally (that is a Playwright trace config problem, different fix)
- artifact uploads failing for non-trace files with other errors (that is a general CI storage problem)

## Variant phrasings

### playwright trace upload failed

General phrasing. ECONNREFUSED specifically points at host/port/connectivity, not auth.

### CI artifacts ECONNREFUSED

Broader phrasing. When the artifact is a Playwright trace, check the upload step config first.

## Why it happens

ECONNREFUSED is a TCP-level error: the client tried to open a connection and the target actively refused it (or nothing was listening). Playwright's trace pipeline has two halves - local recording (writes a zip to disk) and whatever your CI does with the zip afterward (upload step, artifact action, custom script). The refusal happens in the second half, so the trace config is innocent. Common triggers: the upload points at a hostname that only resolves inside a different network, the port is wrong, or the runner's egress firewall blocks the destination.

## Edge cases

- uploading to a service that requires auth at a different endpoint than the docs example: the connection is refused before auth even happens, so do not chase credential rotation first
- large trace zips timing out mid-upload on slow runners: that surfaces as a timeout rather than ECONNREFUSED, but it is the next failure you will meet - consider uploading only on failure
- self-hosted trace viewers behind VPN: CI runners outside the VPN get ECONNREFUSED - either allowlist the runners or upload to CI-native artifact storage instead

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_zHe2inQUlTVgKTKTfqaWVQ
