PlaywrightEx (PlaywrightEx v0.4.0)

Copy Markdown View Source

Main entry point. Elixir client for the Playwright node.js driver.

Use launch_browser/2 to get started after adding PlaywrightEx.Supervisor to your supervision tree.

See the README for getting started and more details.

Summary

Functions

Launches a new browser instance, or returns the pre-launched browser when connected to a remote Playwright server.

Send message to playwright.

Subscribe to playwright responses concerning a resource, identified by its guid, or its descendants. Messages in the format {:playwright_msg, %{} = msg} will be sent to pid.

Types

guid()

@type guid() :: String.t()

send_opt()

@type send_opt() :: {:connection, GenServer.name()} | {:timeout, timeout()}

subscribe_opt()

@type subscribe_opt() :: {:connection, GenServer.name()} | {:pid, pid()}

unknown_opt()

@type unknown_opt() :: {Keyword.key(), Keyword.value()}

Functions

launch_browser(type, opts)

@spec launch_browser(atom(), [PlaywrightEx.BrowserType.launch_opt() | unknown_opt()]) ::
  {:ok, %{guid: guid()}} | {:error, any()}

Launches a new browser instance, or returns the pre-launched browser when connected to a remote Playwright server.

Options

  • :connection (term/0) - The Connection process name. Defaults to PlaywrightEx.Supervisor.Connection. The default value is PlaywrightEx.Supervisor.Connection.

  • :timeout (timeout/0) - Required. Maximum time for the operation (milliseconds).

  • :channel (String.t/0) - Browser distribution channel.

  • :executable_path (String.t/0) - Path to a browser executable to run instead of the bundled one.

  • :headless (boolean/0) - Whether to run browser in headless mode.

  • :slow_mo - Slows down Playwright operations by the specified amount of milliseconds.

send(msg, opts)

@spec send(%{guid: guid(), method: atom()}, [send_opt()]) ::
  %{result: map()} | %{error: map()}

Send message to playwright.

Don't use this! Prefer Channels functions. If a function is missing, consider opening a PR to add it.

Options

  • :connection (term/0) - The Connection process name. Defaults to PlaywrightEx.Supervisor.Connection. The default value is PlaywrightEx.Supervisor.Connection.

  • :timeout (timeout/0) - Required. Maximum time for the operation (milliseconds).

subscribe(guid, opts \\ [])

@spec subscribe(guid(), [subscribe_opt()]) :: :ok

Subscribe to playwright responses concerning a resource, identified by its guid, or its descendants. Messages in the format {:playwright_msg, %{} = msg} will be sent to pid.

Options

  • :connection (term/0) - The Connection process name. Defaults to PlaywrightEx.Supervisor.Connection. The default value is PlaywrightEx.Supervisor.Connection.

  • :pid (pid/0) - The process to send messages to. Defaults to self().