# `PlaywrightEx.Playwright`
[🔗](https://github.com/ftes/playwright_ex/blob/v0.17.0-rc.5/lib/playwright_ex/api/playwright.ex#L3)

Playwright module provides a method to launch a browser instance. The following is a typical example of using Playwright
to drive automation:

```elixir
# Or Playwright.firefox/1 or Playwright.webkit/1.
browser = BrowserType.launch!(Playwright.chromium(playwright))
page = Browser.new_page!(browser)
Page.goto!(page, "http://example.com")
# other actions...
Browser.close!(browser)
```

*Since Playwright 1.8.*

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

# `t`

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

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

# `chromium`

```elixir
@spec chromium(t()) :: PlaywrightEx.BrowserType.t()
```

This object can be used to launch or connect to Chromium, returning instances of [`Browser`](`PlaywrightEx.Browser`).

*Since Playwright 1.8.*

# `devices`

```elixir
@spec devices(t()) :: %{
  optional(String.t()) =&gt; PlaywrightEx.Browser.new_context_options()
}
```

Returns a dictionary of devices to be used with `PlaywrightEx.Browser.new_context/2` or `PlaywrightEx.Browser.new_page/2`.

```elixir
iphone = Playwright.devices(playwright)["iPhone 6"]

browser = BrowserType.launch!(Playwright.webkit(playwright))
context = Browser.new_context!(browser, iphone)
page = BrowserContext.new_page!(context)
Page.goto!(page, "http://example.com")
# other actions...
Browser.close!(browser)
```

In Elixir, a descriptor has the snake_case keys of the options (`user_agent:`), as in the Python client: `Browser.new_context(browser, devices["iPhone 6"])`.

*Since Playwright 1.8.*

# `errors`

```elixir
@spec errors(t()) :: %{TimeoutError: PlaywrightEx.TimeoutError}
```

Playwright methods might fail if they are unable to fulfill a request. For example,
`PlaywrightEx.Locator.wait_for/2` might fail if the selector doesn't match any nodes during the given timeframe.

For certain types of errors Playwright uses specific error classes. These classes are available via
`PlaywrightEx.Playwright.errors/1`.

An example of handling a timeout error:

```elixir
try do
  Page.locator(page, ".foo") |> Locator.wait_for!()
rescue
  _ in PlaywrightEx.TimeoutError ->
    # Do something if this is a timeout.
    nil
end
```

*Since Playwright 1.8.*

# `firefox`

```elixir
@spec firefox(t()) :: PlaywrightEx.BrowserType.t()
```

This object can be used to launch or connect to Firefox, returning instances of [`Browser`](`PlaywrightEx.Browser`).

*Since Playwright 1.8.*

# `request`

```elixir
@spec request(t()) :: PlaywrightEx.APIRequest.t()
```

Exposes API that can be used for the Web API testing.

*Since Playwright 1.16.*

# `selectors`

```elixir
@spec selectors(t()) :: PlaywrightEx.Selectors.t()
```

Selectors can be used to install custom selector engines. See
[extensibility](https://playwright.dev/docs/extensibility) for more information.

*Since Playwright 1.8.*

# `webkit`

```elixir
@spec webkit(t()) :: PlaywrightEx.BrowserType.t()
```

This object can be used to launch or connect to WebKit, returning instances of [`Browser`](`PlaywrightEx.Browser`).

*Since Playwright 1.8.*

---

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