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

Records the events a LiveView handles, from LiveView's telemetry.

LiveView emits `[:phoenix, :live_view, :handle_event, :start]` around
the whole of an event, its `on_mount` hooks included, with the socket
and params. Recording from it rather than from a hook of the recorder's
means an app hook that handles an event and halts, wherever it sits in
`on_mount`, still has its event recorded.

The handler runs in the LiveView process and finds its session in
`PhoenixReplay.Session.Buffer`, so a LiveView that is not recorded costs
one ETS lookup per event. It records `:event`, `%{name: String.t(),
params: map}`, with the params through the session's
`PhoenixReplay.Sanitizer`, and the viewport they carry as a `:viewport`
event; see `PhoenixReplay.Capture.Browser.observe/1`. The events the
recorder's own script sends, the pointer, state and viewport, are
recorded by `PhoenixReplay.Recorder` instead.

Like the other handlers, it reports a failure with
`[:phoenix_replay, :collector, :exception]` rather than raise, which
would detach it for the whole application.

# `attach`

```elixir
@spec attach() :: :ok | {:error, :already_exists}
```

Attaches the telemetry handler. Called by `PhoenixReplay.Capture.Handlers`.

# `detach`

```elixir
@spec detach() :: :ok
```

Detaches the telemetry handler, if attached.

# `handle_event`

```elixir
@spec handle_event([atom()], map(), map(), term()) :: :ok
```

Records a LiveView's event in its process. A failure, such as a custom
sanitizer raising, is reported with
`PhoenixReplay.Telemetry.collector_failed/5` instead of raised.

---

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