Playwright.BrowserType (playwright v0.1.16-preview-3) View Source

Playwright.BrowserType provides functions to launch a specific browser instance or connect to an existing one.

The following is a typical example of using Playwright to drive automation:

alias Playwright.{Browser, BrowserType, Page}

{connection, browser} = BrowserType.launch(:chromium)
{:ok, page} = Browser.new_page(browser)

Page.goto(page, "https://example.com")
# other actions...

Browser.close(browser)

Example

Open a new chromium via the CLI driver:

{connection, browser} = Playwright.BrowserType.launch()

Connect to a running playwright instances:

{connection, browser} =
  Playwright.BrowserType.connect("ws://localhost:3000/playwright")

Link to this section Summary

Types

The web client type used for launch/1 and connect/2 functions.

A map/struct providing call options

t()

%Playwright.BrowserType{}

A string URL

A websocket endpoint (URL)

Functions

Attaches Playwright to an existing browser instance over a websocket.

Callback implementation for c:Playwright.ChannelOwner.init/2.

Launches a new browser instance via the Playwright driver CLI.

Link to this section Types

Specs

client() :: :chromium | :firefox | :webkit

The web client type used for launch/1 and connect/2 functions.

Specs

connect_options() :: map()

Options for connect/2

Specs

options() :: map()

A map/struct providing call options

Specs

t() :: %Playwright.BrowserType{
  connection: term(),
  guid: term(),
  listeners: term(),
  parent: term(),
  type: term()
}

%Playwright.BrowserType{}

Specs

url() :: String.t()

A string URL

Specs

ws_endpoint() :: url()

A websocket endpoint (URL)

Link to this section Functions

Link to this function

connect(ws_endpoint, options \\ %{})

View Source

Specs

Attaches Playwright to an existing browser instance over a websocket.

Returns

  • {connection, %Playwright.Browser{}}

Arguments

key / nametypedescription
ws_endpointparamBrowserType.ws_endpoint()A browser websocket endpoint to connect to.
:headersoptionmap()Additional HTTP headers to be sent with websocket connect request
:slow_mowoptioninteger()Slows down Playwright operations by the specified amount of milliseconds. Useful so that you can see what is going on. (default: 0)
:loggeroptionLogger sink for Playwright logging
:timeoutoptioninteger()Maximum time in milliseconds to wait for the connection to be established. Pass 0 to disable timeout. (default: 30_000 (30 seconds))
Link to this function

init(owner, initializer)

View Source

Specs

init(struct(), map()) :: {atom(), struct()}

Callback implementation for c:Playwright.ChannelOwner.init/2.

Specs

launch(client() | nil) :: {pid(), Playwright.Browser.t()}

Launches a new browser instance via the Playwright driver CLI.

Example

# Use `:ignore_default_args` option to filter out `--mute-audio` from
# default arguments:
browser =
  Playwright.launch(:chromium, %{ignore_default_args = ["--mute-audio"]})

Returns

  • {connection, %Playwright.Browser{}}

Arguments

... (many)

NOTE

Chromium-only Playwright can also be used to control the Google Chrome or Microsoft Edge browsers, but it works best with the version of Chromium it is bundled with. There is no guarantee it will work with any other version. Use :executable_path option with extreme caution.

If Google Chrome (rather than Chromium) is preferred, a Chrome Canary or Dev Channel build is suggested.

Stock browsers like Google Chrome and Microsoft Edge are suitable for tests that require proprietary media codecs for video playback. See this article for other differences between Chromium and Chrome. This article describes some differences for Linux users.