## TL;DR
Playwright could not write the video file: the output directory does not exist in the CI job, is not writable, or the disk is full. Videos are large, so this surfaces in CI where disks are small and artifact directories differ from local ones. Point video output at a directory the CI job creates, set video to retain-on-failure to shrink output, and check disk space before changing anything else.

## The query
```text
playwright video recording failed unable to write in CI artifacts  -  how to fix
```

## Use this when
- video recording failed or videos are missing from CI artifacts
- the error mentions unable to write
- the same config records video fine locally

## Not for
- video recording is disabled in the config (enable it; nothing is broken)
- the video files exist but are corrupt or unplayable (a codec problem, not a write problem)
- artifacts upload fails while videos exist on disk (fix the upload step, not the recording)

## Steps

### 1. Read the exact write error
The failure message distinguishes the three causes: missing directory, permission denied, or no space left. Do not guess.
```text
video recording failed: unable to write to test-results/videos/
```
Expected output: you know which of the three causes you are dealing with.

### 2. Ensure the directory exists and is writable
Create the output directory in the CI job before the tests run, and confirm the test user can write to it.
```yaml
- name: Prepare video dir
  run: mkdir -p test-results/videos
- name: Run Playwright
  run: npx playwright test
```
Expected output: the directory exists with write permission for the CI user.

### 3. Shrink video output with retain-on-failure
Recording every test's video multiplies disk usage. Keeping video only for failures cuts it dramatically while preserving the debugging value.
```ts
// playwright.config.ts
export default defineConfig({
  use: { video: 'retain-on-failure' },
});
```
Expected output: only failing tests produce video files and disk usage drops.

### 4. Check disk space in the CI job
Videos plus browser downloads plus node_modules can fill a small CI disk. Verify headroom directly.
```bash
df -h .
du -sh test-results/ 2>/dev/null
```
Expected output: free space comfortably exceeds the video output size.

## Tool compatibility
- Playwright 1.40 - 1.55
- any CI provider with artifact upload

## Variant phrasings
- video recording failed unable to write in CI
- playwright video not saved in CI artifacts
- unable to write video file playwright CI

## Why it happens
Playwright writes videos to the output directory as tests run, and CI jobs often run with different working directories, read-only mounts, or tight disks compared to local machines. The recording pipeline itself is fine; it is the filesystem underneath that differs. Because videos are written continuously during the run, a full or unwritable disk fails the recording rather than the test, which is why the suite can look green while the videos are missing.

## Edge cases / pitfalls
- artifact upload steps that run before the test process exits can race the video finalization; order upload after the test step
- retain-on-failure still writes video for retried-then-passed tests depending on configuration; check what you actually need
- mounted volumes in docker CI may be read-only or size-capped; write videos to the container's writable layer and copy out
- very long tests produce very large videos; splitting the spec file reduces per-file size

## Provenance

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