PhoenixReplay.Export (PhoenixReplay v0.6.2)

Copy Markdown View Source

Exports recordings as videos of the replayed page and the pointer.

A recording holds no pixels: the player renders it again from recorded assigns. An export does the same in a headless browser and films it.

  1. PhoenixReplay.Export.Schedule plans the video: a constant frame rate from the first render, idle stretches shortened, and a screenshot only where the picture changes.
  2. PhoenixReplay.Export.Screenshots loads the replay into Chromium through playwright_ex, at the recorded viewport and pixel ratio, steps it through the plan with the player's own pointer overlay, and screenshots each change.
  3. PhoenixReplay.Export.Encoder encodes the screenshots with ffmpeg into an H.264 MP4, run by MuonTrap so it never outlives the export.

The browser loads the replay from PhoenixReplay.Web.Export.Endpoint, a private endpoint on 127.0.0.1 started with the first export, so it needs no route or login in your app.

Exports wait their turn in a PhoenixReplay.Export.Queue: by default PhoenixReplay.Export.Queue.Local, in memory, one at a time or :max_concurrency at once; or PhoenixReplay.Export.Queue.Oban, in your Oban queue. Each job's progress is broadcast; the player's Export video and mix phoenix_replay.export both follow it. Finished videos are deleted after :ttl.

Setup

Add {:playwright_ex, "~> 0.14"} and {:muontrap, "~> 1.6"}, install Playwright's Chromium (npx playwright install chromium) and ffmpeg, and name your endpoint. MuonTrap runs on Linux and macOS.

config :phoenix_replay, export: [endpoint: MyAppWeb.Endpoint]

See :export in PhoenixReplay.Config for the other options. Only saved recordings are exported, not sessions still running.

Summary

Types

Why exporting is not possible.

Functions

Whether videos can be exported with config, or why not.

Whether videos can be exported with config.

Cancels an export that is queued or running. A running one closes its browser and stops encoding first, and ends :cancelled.

Explains why exporting is not possible.

The export with id, if it is still kept.

The latest export of a recording, if one is kept.

Exports a saved recording with options, by default those the configuration sets, or returns the export of it already queued or running. See PhoenixReplay.Export.Options.

Subscribes the caller to the exports of a recording: each change to one arrives as {PhoenixReplay.Export, %PhoenixReplay.Export.Job{}}.

Types

unavailable()

@type unavailable() ::
  :disabled | :no_endpoint | :no_playwright | :no_muontrap | :no_ffmpeg

Why exporting is not possible.

Functions

available(config)

@spec available(PhoenixReplay.Config.t()) :: :ok | {:error, unavailable()}

Whether videos can be exported with config, or why not.

available?(config)

@spec available?(PhoenixReplay.Config.t()) :: boolean()

Whether videos can be exported with config.

cancel(id, config \\ Config.load())

Cancels an export that is queued or running. A running one closes its browser and stops encoding first, and ends :cancelled.

describe(atom)

@spec describe(unavailable()) :: String.t()

Explains why exporting is not possible.

get(id, config \\ Config.load())

The export with id, if it is still kept.

latest(recording_id, config \\ Config.load())

The latest export of a recording, if one is kept.

start(recording_id, config \\ Config.load(), options \\ nil)

Exports a saved recording with options, by default those the configuration sets, or returns the export of it already queued or running. See PhoenixReplay.Export.Options.

subscribe(recording_id)

@spec subscribe(PhoenixReplay.Recording.id()) :: :ok | {:error, term()}

Subscribes the caller to the exports of a recording: each change to one arrives as {PhoenixReplay.Export, %PhoenixReplay.Export.Job{}}.