Playwright.Screencast (Playwright v1.65.0-rc.3)

Copy Markdown View Source

Interface for capturing screencast frames from a page.

Since Playwright 1.59.

The examples alias the modules they use (alias Playwright.{Locator, Page}).

Summary

Types

Options of show_actions/2, see its docs.

Options of show_chapter/3, see its docs.

Options of show_overlay/3, see its docs.

Options of start/2, see its docs.

t()

A Screencast handle. Compare handles with ==, their fields are internal.

Functions

Removes action decorations.

Like hide_actions/1, but returns the value and raises on error.

Hides overlays without removing them.

Like hide_overlays/1, but returns the value and raises on error.

Enables visual annotations on interacted elements. Returns a disposable that stops showing actions when disposed.

Like show_actions/2, but returns the value and raises on error.

Shows a chapter overlay with a title and optional description, centered on the page with a blurred backdrop. Useful for narrating video recordings. The overlay is removed after the specified duration, or 2000ms.

Like show_chapter/3, but returns the value and raises on error.

Adds an overlay with the given HTML content. The overlay is displayed on top of the page until removed. Returns a disposable that removes the overlay when disposed.

Like show_overlay/3, but returns the value and raises on error.

Shows overlays.

Like show_overlays/1, but returns the value and raises on error.

Starts the screencast. When :path is provided, it saves video recording to the specified file. When :on_frame is provided, delivers JPEG-encoded frames to the callback. Both can be used together.

Like start/2, but returns the value and raises on error.

Stops the screencast and video recording if active. If a video was being recorded, saves it to the path specified in Playwright.Screencast.start/2.

Like stop/1, but returns the value and raises on error.

Types

show_actions_options()

@type show_actions_options() ::
  [
    cursor: :none | :pointer,
    duration: number(),
    font_size: integer(),
    position:
      :top_left | :top | :top_right | :bottom_left | :bottom | :bottom_right,
    style: %{
      optional(:point) => String.t(),
      optional(:highlight) => String.t(),
      optional(:title) => String.t()
    }
  ]
  | %{
      optional(:cursor) => :none | :pointer,
      optional(:duration) => number(),
      optional(:font_size) => integer(),
      optional(:position) =>
        :top_left | :top | :top_right | :bottom_left | :bottom | :bottom_right,
      optional(:style) => %{
        optional(:point) => String.t(),
        optional(:highlight) => String.t(),
        optional(:title) => String.t()
      }
    }

Options of show_actions/2, see its docs.

show_chapter_options()

@type show_chapter_options() ::
  [description: String.t(), duration: number()]
  | %{optional(:description) => String.t(), optional(:duration) => number()}

Options of show_chapter/3, see its docs.

show_overlay_options()

@type show_overlay_options() ::
  [{:duration, number()}] | %{optional(:duration) => number()}

Options of show_overlay/3, see its docs.

start_options()

@type start_options() ::
  [
    fps: integer(),
    on_frame: (%{
                 data: binary(),
                 timestamp: number(),
                 viewportWidth: integer(),
                 viewportHeight: integer()
               } ->
                 term()),
    path: String.t(),
    quality: integer(),
    size: %{width: integer(), height: integer()}
  ]
  | %{
      optional(:fps) => integer(),
      optional(:on_frame) => (%{
                                data: binary(),
                                timestamp: number(),
                                viewportWidth: integer(),
                                viewportHeight: integer()
                              } ->
                                term()),
      optional(:path) => String.t(),
      optional(:quality) => integer(),
      optional(:size) => %{width: integer(), height: integer()}
    }

Options of start/2, see its docs.

t()

@type t() :: %Playwright.Screencast{
  conn: term(),
  guid: term(),
  initializer: term(),
  table: term(),
  type: term()
}

A Screencast handle. Compare handles with ==, their fields are internal.

Functions

hide_actions(screencast)

@spec hide_actions(t()) :: :ok | {:error, Playwright.error()}

Removes action decorations.

Since Playwright 1.59.

hide_actions!(screencast)

@spec hide_actions!(t()) :: :ok

Like hide_actions/1, but returns the value and raises on error.

hide_overlays(screencast)

@spec hide_overlays(t()) :: :ok | {:error, Playwright.error()}

Hides overlays without removing them.

Since Playwright 1.59.

hide_overlays!(screencast)

@spec hide_overlays!(t()) :: :ok

Like hide_overlays/1, but returns the value and raises on error.

show_actions(screencast, options \\ [])

@spec show_actions(t(), show_actions_options()) ::
  {:ok, Playwright.Disposable.t()} | {:error, Playwright.error()}

Enables visual annotations on interacted elements. Returns a disposable that stops showing actions when disposed.

Since Playwright 1.59.

Options

  • :cursor (:none | :pointer) - Since Playwright 1.61. Cursor decoration shown for pointer actions. :pointer (the default) renders a mouse pointer that animates from the previous action point to the next one. :none disables the cursor decoration.

  • :duration (number/0) - How long each annotation is displayed in milliseconds. Defaults to 500.
  • :font_size (integer/0) - Font size of the action title in pixels. Defaults to 24.
  • :position (:top_left | :top | :top_right | :bottom_left | :bottom | :bottom_right) - Position of the action title overlay. Defaults to :top_right.

  • :style (map/0) - Since Playwright 1.64. Styles of the action decorations. All decorations fade out over :duration.Usage
    Page.screencast(page)
    |> Screencast.show_actions!(
      style: %{
        point: "width: 20px; height: 20px; border-radius: 50%; background: red",
        highlight: "outline: 2px solid #333; background: rgba(0, 128, 255, .15)",
        title: "font-size: 16px"
      }
    )
    • :point - CSS declarations for the marker at the action point. The marker is positioned at the action point, has zero size and is centered on the point, so its size and look come from this style. Not shown when omitted.
    • :highlight - CSS declarations for the box that covers the target element. The box is positioned and sized to the element bounds. Not shown when omitted.
    • :title - CSS declarations for the action title, for example 'font-size: 32px; background: #333'. The title is placed according to :position.

show_actions!(screencast, options \\ [])

@spec show_actions!(t(), show_actions_options()) :: Playwright.Disposable.t()

Like show_actions/2, but returns the value and raises on error.

show_chapter(screencast, title, options \\ [])

@spec show_chapter(t(), String.t(), show_chapter_options()) ::
  :ok | {:error, Playwright.error()}

Shows a chapter overlay with a title and optional description, centered on the page with a blurred backdrop. Useful for narrating video recordings. The overlay is removed after the specified duration, or 2000ms.

Since Playwright 1.59.

Arguments

  • title - Title text displayed prominently in the overlay.

Options

  • :description (String.t/0) - Optional description text displayed below the title.
  • :duration (number/0) - Duration in milliseconds after which the overlay is automatically removed. Defaults to 2000.

show_chapter!(screencast, title, options \\ [])

@spec show_chapter!(t(), String.t(), show_chapter_options()) :: :ok

Like show_chapter/3, but returns the value and raises on error.

show_overlay(screencast, html, options \\ [])

@spec show_overlay(t(), String.t(), show_overlay_options()) ::
  {:ok, Playwright.Disposable.t()} | {:error, Playwright.error()}

Adds an overlay with the given HTML content. The overlay is displayed on top of the page until removed. Returns a disposable that removes the overlay when disposed.

Since Playwright 1.59.

Arguments

  • html - HTML content for the overlay.

Options

  • :duration (number/0) - Duration in milliseconds after which the overlay is automatically removed. Overlay stays until dismissed if not provided.

show_overlay!(screencast, html, options \\ [])

@spec show_overlay!(t(), String.t(), show_overlay_options()) ::
  Playwright.Disposable.t()

Like show_overlay/3, but returns the value and raises on error.

show_overlays(screencast)

@spec show_overlays(t()) :: :ok | {:error, Playwright.error()}

Shows overlays.

Since Playwright 1.59.

show_overlays!(screencast)

@spec show_overlays!(t()) :: :ok

Like show_overlays/1, but returns the value and raises on error.

start(screencast, options \\ [])

@spec start(t(), start_options()) ::
  {:ok, Playwright.Disposable.t()} | {:error, Playwright.error()}

Starts the screencast. When :path is provided, it saves video recording to the specified file. When :on_frame is provided, delivers JPEG-encoded frames to the callback. Both can be used together.

Usage

# Record video
Page.screencast(page) |> Screencast.start!(path: "video.webm", size: %{width: 1280, height: 800})
# ... perform actions ...
Page.screencast(page) |> Screencast.stop!()
# Capture frames
Page.screencast(page)
|> Screencast.start!(
  on_frame: fn %{data: data, timestamp: timestamp, viewportWidth: width, viewportHeight: height} ->
    IO.puts("frame size: #{byte_size(data)} (#{width}x#{height}) at #{timestamp}")
  end,
  size: %{width: 800, height: 600}
)

# ... perform actions ...
Page.screencast(page) |> Screencast.stop!()

Since Playwright 1.59.

Options

  • :fps (integer/0) - Since Playwright 1.64. Frame rate of the video recording in frames per second. Only used together with :path. Defaults to 25.

    Higher frame rates make animations and scrolling smoother at the cost of more CPU spent on encoding. Combine with :size to record high resolution videos. The video can only contain as many distinct frames as the browser produces; Firefox and WebKit currently capture up to 25 frames per second.

  • :on_frame ((%{data: binary(), timestamp: number(), viewportWidth: integer(), viewportHeight: integer()} -> term())) - Callback that receives JPEG-encoded frame data along with the page viewport size at the time of capture.

  • :path (String.t/0) - Path where the video should be saved when the screencast is stopped. When provided, video recording is started.

  • :quality (integer/0) - The quality of the image, between 0-100.

  • :size (map/0) - Specifies the dimensions of screencast frames. The actual frame is scaled to preserve the page's aspect ratio and may be smaller than these bounds. If a screencast is already active (e.g. started by tracing or video recording), the existing configuration takes precedence and the frame size may exceed these bounds or this option may be ignored. If not specified the size will be equal to page viewport scaled down to fit into 800×800.

    • :width - Max frame width in pixels.
    • :height - Max frame height in pixels.

start!(screencast, options \\ [])

@spec start!(t(), start_options()) :: Playwright.Disposable.t()

Like start/2, but returns the value and raises on error.

stop(screencast)

@spec stop(t()) :: :ok | {:error, Playwright.error()}

Stops the screencast and video recording if active. If a video was being recorded, saves it to the path specified in Playwright.Screencast.start/2.

Since Playwright 1.59.

stop!(screencast)

@spec stop!(t()) :: :ok

Like stop/1, but returns the value and raises on error.