> ## Documentation Index
> Fetch the complete documentation index at: https://docs.spoolpdf.nandra.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Waits, cookies, and auth

> SPA waits, extra HTTP headers, cookies, and HTTP Basic auth.

## Wait for the page

`wait_delay` is a Go duration (`2s`, `500ms`), max 30s. `wait_for_selector` waits until a matching element exists. `wait_for_expression` waits until a JavaScript expression is truthy (async expressions that return a Promise are awaited). `wait_for_network_idle: true` waits until Chromium reports zero connections for 500ms — skip it on pages that keep a websocket open.

```bash theme={null}
curl -sS -o spa.pdf \
  -X POST "$SPOOLPDF_BASE_URL/v1/render" \
  -H "Authorization: Bearer $SPOOLPDF_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com/invoice/preview",
    "wait_for_selector": "#invoice-ready",
    "wait_delay": "500ms"
  }'
```

```json theme={null}
{"html": "<html>…</html>", "wait_for_expression": "window.status === 'ready'"}
```

If the wait never becomes true, the call returns `502` `render_failed`.

## Headers and cookies

Do not put `Cookie` in `extra_http_headers`. Use `cookies` (`name`, `value`, and `domain` are required). Hop-by-hop header names are rejected.

```json theme={null}
{
  "url": "https://app.example.com/statement",
  "extra_http_headers": {"Authorization": "Bearer app-token"},
  "cookies": [
    {"name": "sid", "value": "abc", "domain": "app.example.com", "http_only": true, "same_site": "Lax"}
  ]
}
```

## HTTP Basic auth

```json theme={null}
{"url": "https://app.example.com/invoice", "auth": {"username": "user", "password": "secret"}}
```

`auth` cannot be combined with `extra_http_headers.Authorization`.

## Fail on HTTP status

`raise_for_status: true` fails the render on 3xx/4xx/5xx of the main URL. `false` allows error pages. Omit to keep the default (fail on 4xx/5xx).

`emulate_media` is `print` (default) or `screen`.
