# Fix the locale screenshot agent stuck on a date picker CDP timeout

## TL;DR

The date picker never settles because it re-renders on locale data load, so wait for network idle plus the picker element instead of a fixed timeout. CDP timeouts fire while the picker is still fetching locale data. Wait for the picker to be visible and stable, then screenshot.

## The error

```text
Locale screenshot agent: CDP timeout waiting for date picker
picker opens but dates never render in the target locale
```

## Fix it

### Step 1: Watch what the picker does on open

```bash
node -e "console.log('open the picker manually, watch network: it fetches locale data after opening')"
```

Expected: You see the late locale fetch.

### Step 2: Wait for the picker content, not a fixed delay

```bash
node -e "console.log('pattern: click to open, waitForSelector the day cells in the target locale, then screenshot')"
```

Expected: The wait targets the real readiness signal.

### Step 3: Raise the CDP timeout for locale-heavy widgets

```bash
node -e "console.log('date pickers with locale data deserve a longer protocol timeout than plain buttons')"
```

Expected: Slow locale loads stop timing out.

### Step 4: Re-run the screenshot flow

```bash
node scripts/locale-shots.js --widget datepicker | tail -3
```

Expected: The picker renders and the screenshot captures it.

## When to use this

- A screenshot agent CDP-times-out on a date picker
- The picker opens but locale dates never render

## When NOT to use this

- The picker never opens, that is an interaction bug
- Dates render but wrong, check the locale data

## Tool and version compatibility

- Chrome DevTools Protocol, Playwright/Puppeteer
- Locale-aware date picker widgets

## Variant phrasings

### timeout on other locale widgets

Same pattern. Wait for the widget's rendered content, not a timer.

### picker renders but in the wrong locale

The locale data fetch used the default locale. Pass the locale before opening.

## Why it happens

Locale-aware pickers fetch month and day names asynchronously after opening. A fixed wait or a short CDP timeout fires during that fetch, so the agent times out on a widget that was about to be ready.

## Edge cases

- Cache the locale data between runs, refetching every screenshot is slow
- Some pickers virtualize months, scroll them into view before screenshotting
- CDP timeouts also cover the screenshot itself, keep them generous for big pages

## Provenance

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