# `PlaywrightEx.Browser`
[🔗](https://github.com/probably-not/playwright_ex/blob/v0.5.0-fork.2/lib/playwright_ex/channels/browser.ex#L1)

Interact with a Playwright `Browser`.

There is no official documentation, since this is considered Playwright internal.

Reference: https://github.com/microsoft/playwright/blob/main/packages/playwright-core/src/client/browser.ts

# `close_opt`

```elixir
@type close_opt() ::
  {:connection, GenServer.name()} | {:timeout, timeout()} | {:reason, binary()}
```

# `new_context_opt`

```elixir
@type new_context_opt() ::
  {:connection, GenServer.name()}
  | {:timeout, timeout()}
  | {:accept_downloads, boolean()}
  | {:base_url, binary()}
  | {:bypass_csp, boolean()}
  | {:color_scheme, term()}
  | {:device_scale_factor, float()}
  | {:extra_http_headers, term()}
  | {:http_credentials, term()}
  | {:ignore_https_errors, boolean()}
  | {:is_mobile, boolean()}
  | {:java_script_enabled, boolean()}
  | {:locale, binary()}
  | {:user_agent, binary()}
  | {:viewport, term()}
```

# `close`

```elixir
@spec close(PlaywrightEx.guid(), [close_opt() | PlaywrightEx.unknown_opt()]) ::
  {:ok, any()} | {:error, any()}
```

Closes the browser and all of its contexts.

Reference: https://playwright.dev/docs/api/class-browser#browser-close

## Options
* `:connection` (`t:term/0`) - The Connection process name. Defaults to `PlaywrightEx.Supervisor.Connection`. The default value is `PlaywrightEx.Supervisor.Connection`.

* `:timeout` (`t:timeout/0`) - Required. Maximum time for the operation (milliseconds).

* `:reason` (`t:String.t/0`) - The reason to be reported to the operations interrupted by the browser closure.

# `new_context`

```elixir
@spec new_context(PlaywrightEx.guid(), [
  new_context_opt() | PlaywrightEx.unknown_opt()
]) ::
  {:ok, %{guid: PlaywrightEx.guid(), tracing: %{guid: PlaywrightEx.guid()}}}
  | {:error, any()}
```

Creates a new browser context. It won't share cookies/cache with other browser contexts.

Reference: https://playwright.dev/docs/api/class-browser#browser-new-context

## Options
* `:connection` (`t:term/0`) - The Connection process name. Defaults to `PlaywrightEx.Supervisor.Connection`. The default value is `PlaywrightEx.Supervisor.Connection`.

* `:timeout` (`t:timeout/0`) - Required. Maximum time for the operation (milliseconds).

* `:accept_downloads` (`t:boolean/0`) - Whether to automatically download all the attachments. Defaults to `true`.

* `:base_url` (`t:String.t/0`) - When using `Page.goto/3`, `Page.route/3`, `Page.wait_for_url/3`, etc., it takes the base URL into consideration.

* `:bypass_csp` (`t:boolean/0`) - Toggles bypassing page's Content-Security-Policy. Defaults to `false`.

* `:color_scheme` - Emulates `'prefers-colors-scheme'` media feature. Defaults to `:light`.

* `:device_scale_factor` (`t:float/0`) - Specify device scale factor (can be thought of as dpr). Defaults to `1`.

* `:extra_http_headers` (`t:term/0`) - An object containing additional HTTP headers to be sent with every request.

* `:http_credentials` (`t:term/0`) - Credentials for HTTP authentication. Map with `:username` and `:password`.

* `:ignore_https_errors` (`t:boolean/0`) - Whether to ignore HTTPS errors when sending network requests. Defaults to `false`.

* `:is_mobile` (`t:boolean/0`) - Whether the meta viewport tag is taken into account and touch events are enabled. Defaults to `false`.

* `:java_script_enabled` (`t:boolean/0`) - Whether or not to enable JavaScript in the context. Defaults to `true`.

* `:locale` (`t:String.t/0`) - Specify user locale, for example `en-GB`, `de-DE`, etc.

* `:user_agent` (`t:String.t/0`) - Specific user agent to use in this context.

* `:viewport` (`t:term/0`) - Sets a consistent viewport for each page. Map with `:width` and `:height`, or `nil` to disable.

---

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