# `PhoenixReplay.Capture.State`
[🔗](https://github.com/elixir-vibe/phoenix_replay/blob/v0.6.2/lib/phoenix_replay/capture/state.ex#L1)

Records state that lives only in the browser, which replaying the view's
`render/1` cannot rebuild.

The client module's `replayRecorder/1` records what is typed and chosen
in form controls on its own, under
`PhoenixReplay.Recording.State.inputs_key/0`. App code reports other
state with `replayState(key, changes)`, and code that cannot import
PhoenixReplay, such as another library, with a window event:

    window.dispatchEvent(
      new CustomEvent("phx_replay:state", {
        detail: {key: "search", changes: {query: "shoes"}}
      })
    )

`key` names the state, and `changes` holds its fields to merge into what
was recorded under `key` before: a shallow delta. The client keeps the
latest state of each key, so a recording starts with the state as it
is; while the page's LiveView is recorded it timestamps each entry and
sends them in batches as a `"phx_replay:state"` event, which
`PhoenixReplay.Recorder` hands here and halts, so the view never sees
it. A batch is:

  * `"span"` — milliseconds from the batch's first entry to sending it
  * `"e"` — entries, `[dt, key, changes]`, `dt` counting milliseconds
    from the batch's first entry

Batches come from the browser: `key` must be a string of up to
`:max_key` bytes and `changes` a JSON object of at most
`:max_entry_bytes`, nested no deeper than 32 levels, or the entry is
dropped; a batch keeps at most `:max_entries` entries and `:max_bytes`.
Keys stay strings, and `changes` go through the session's
`PhoenixReplay.Sanitizer` with `sanitize_params/1`, and through its
`PhoenixReplay.Redactor` when it is saved.

Each batch is recorded as a `:state` event, outside `:max_events`, up to
`:limit` per session. A changed form control, or a change to a key
reported before, makes a session interactive for `:keep`; the first
report of any other key, the state the page started with, does not. See
`PhoenixReplay.Recording.State` for how the player replays them.

# `capture`

```elixir
@spec capture(pid(), map(), PhoenixReplay.Config.state()) :: :ok | :dropped | :error
```

Records a batch sent by the browser for the session `pid` records.

# `event`

```elixir
@spec event() :: String.t()
```

The event name batches arrive as.

# `parse`

```elixir
@spec parse(map(), PhoenixReplay.Config.state(), module()) :: {:ok, map()} | :error
```

Validates a batch: returns its entries within the `state` limits, their
changes sanitized with `sanitizer`, or `:error` when none is usable.

# `settings`

```elixir
@spec settings(PhoenixReplay.Config.state()) :: map()
```

The settings the browser records with, for `Phoenix.LiveView.push_event/3`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
