# `Playwright.Browser`
[🔗](https://github.com/ftes/playwright_ex/blob/v1.65.0-rc.3/lib/playwright/api/browser.ex#L7)

A Browser is created via `Playwright.BrowserType.launch/2`. An example of using a [`Browser`](`Playwright.Browser`) to create a [`Page`](`Playwright.Page`):

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

*Since Playwright 1.8.*

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

## Events

### `:context`

*Since Playwright 1.60.* Emitted when a new browser context is created.

### `:disconnected`

Emitted when Browser gets disconnected from the browser application. This might happen because of one of the following:

* Browser application is closed or crashed.
* The `Playwright.Browser.close/2` method was called.

# `bind_options`

```elixir
@type bind_options() ::
  [
    host: String.t(),
    metadata: %{optional(String.t()) =&gt; term()},
    port: integer(),
    workspace_dir: String.t()
  ]
  | %{
      optional(:host) =&gt; String.t(),
      optional(:metadata) =&gt; %{optional(String.t()) =&gt; term()},
      optional(:port) =&gt; integer(),
      optional(:workspace_dir) =&gt; String.t()
    }
```

Options of `bind/3`, see its docs.

# `close_options`

```elixir
@type close_options() :: [{:reason, String.t()}] | %{optional(:reason) =&gt; String.t()}
```

Options of `close/2`, see its docs.

# `event`

```elixir
@type event() :: :context | :disconnected
```

An event name, see the module docs.

# `new_context_options`

```elixir
@type new_context_options() ::
  [
    accept_downloads: boolean(),
    base_url: String.t(),
    bypass_csp: boolean(),
    client_certificates: [
      %{
        :origin =&gt; String.t(),
        optional(:certPath) =&gt; String.t(),
        optional(:cert) =&gt; binary(),
        optional(:keyPath) =&gt; String.t(),
        optional(:key) =&gt; binary(),
        optional(:pfxPath) =&gt; String.t(),
        optional(:pfx) =&gt; binary(),
        optional(:passphrase) =&gt; String.t()
      }
    ],
    color_scheme: :null | :light | :dark | :no_preference,
    contrast: :null | :no_preference | :more,
    device_scale_factor: number(),
    extra_http_headers: %{optional(String.t()) =&gt; String.t()},
    forced_colors: :null | :active | :none,
    geolocation: %{
      :latitude =&gt; number(),
      :longitude =&gt; number(),
      optional(:accuracy) =&gt; number()
    },
    has_touch: boolean(),
    http_credentials:
      %{
        :username =&gt; String.t(),
        :password =&gt; String.t(),
        optional(:origin) =&gt; String.t(),
        optional(:send) =&gt; String.t()
      }
      | [
          %{
            :username =&gt; String.t(),
            :password =&gt; String.t(),
            optional(:origin) =&gt; String.t(),
            optional(:send) =&gt; String.t()
          }
        ],
    ignore_https_errors: boolean(),
    is_mobile: boolean(),
    java_script_enabled: boolean(),
    locale: String.t(),
    logger: %{
      isEnabled: (String.t(), String.t() -&gt; boolean()),
      log: (String.t(),
            String.t(),
            String.t()
            | Exception.t(),
            [map()],
            %{optional(:color) =&gt; String.t()} -&gt;
              term())
    },
    offline: boolean(),
    permissions: [String.t()],
    proxy: %{
      :server =&gt; String.t(),
      optional(:bypass) =&gt; String.t(),
      optional(:username) =&gt; String.t(),
      optional(:password) =&gt; String.t()
    },
    record_har: %{
      optional(:omitContent) =&gt; boolean(),
      optional(:content) =&gt; String.t(),
      :path =&gt; String.t(),
      optional(:mode) =&gt; String.t(),
      optional(:urlFilter) =&gt; String.t() | Regex.t() | Playwright.RegExp.t()
    },
    record_video: %{
      optional(:dir) =&gt; String.t(),
      optional(:size) =&gt; %{width: integer(), height: integer()},
      optional(:fps) =&gt; integer(),
      optional(:showActions) =&gt; %{
        optional(:duration) =&gt; number(),
        optional(:position) =&gt; String.t(),
        optional(:fontSize) =&gt; integer(),
        optional(:cursor) =&gt; String.t(),
        optional(:style) =&gt; %{
          optional(:point) =&gt; String.t(),
          optional(:highlight) =&gt; String.t(),
          optional(:title) =&gt; String.t()
        }
      }
    },
    reduced_motion: :null | :reduce | :no_preference,
    screen: %{width: integer(), height: integer()},
    service_workers: :allow | :block,
    storage_state: String.t() | map(),
    strict_selectors: boolean(),
    timezone_id: String.t(),
    user_agent: String.t(),
    viewport: :null | %{width: integer(), height: integer()},
    default_browser_type: String.t()
  ]
  | %{
      optional(:accept_downloads) =&gt; boolean(),
      optional(:base_url) =&gt; String.t(),
      optional(:bypass_csp) =&gt; boolean(),
      optional(:client_certificates) =&gt; [
        %{
          :origin =&gt; String.t(),
          optional(:certPath) =&gt; String.t(),
          optional(:cert) =&gt; binary(),
          optional(:keyPath) =&gt; String.t(),
          optional(:key) =&gt; binary(),
          optional(:pfxPath) =&gt; String.t(),
          optional(:pfx) =&gt; binary(),
          optional(:passphrase) =&gt; String.t()
        }
      ],
      optional(:color_scheme) =&gt; :null | :light | :dark | :no_preference,
      optional(:contrast) =&gt; :null | :no_preference | :more,
      optional(:device_scale_factor) =&gt; number(),
      optional(:extra_http_headers) =&gt; %{optional(String.t()) =&gt; String.t()},
      optional(:forced_colors) =&gt; :null | :active | :none,
      optional(:geolocation) =&gt; %{
        :latitude =&gt; number(),
        :longitude =&gt; number(),
        optional(:accuracy) =&gt; number()
      },
      optional(:has_touch) =&gt; boolean(),
      optional(:http_credentials) =&gt;
        %{
          :username =&gt; String.t(),
          :password =&gt; String.t(),
          optional(:origin) =&gt; String.t(),
          optional(:send) =&gt; String.t()
        }
        | [
            %{
              :username =&gt; String.t(),
              :password =&gt; String.t(),
              optional(:origin) =&gt; String.t(),
              optional(:send) =&gt; String.t()
            }
          ],
      optional(:ignore_https_errors) =&gt; boolean(),
      optional(:is_mobile) =&gt; boolean(),
      optional(:java_script_enabled) =&gt; boolean(),
      optional(:locale) =&gt; String.t(),
      optional(:logger) =&gt; %{
        isEnabled: (String.t(), String.t() -&gt; boolean()),
        log: (String.t(),
              String.t(),
              String.t()
              | Exception.t(),
              [map()],
              %{optional(:color) =&gt; String.t()} -&gt;
                term())
      },
      optional(:offline) =&gt; boolean(),
      optional(:permissions) =&gt; [String.t()],
      optional(:proxy) =&gt; %{
        :server =&gt; String.t(),
        optional(:bypass) =&gt; String.t(),
        optional(:username) =&gt; String.t(),
        optional(:password) =&gt; String.t()
      },
      optional(:record_har) =&gt; %{
        optional(:omitContent) =&gt; boolean(),
        optional(:content) =&gt; String.t(),
        :path =&gt; String.t(),
        optional(:mode) =&gt; String.t(),
        optional(:urlFilter) =&gt; String.t() | Regex.t() | Playwright.RegExp.t()
      },
      optional(:record_video) =&gt; %{
        optional(:dir) =&gt; String.t(),
        optional(:size) =&gt; %{width: integer(), height: integer()},
        optional(:fps) =&gt; integer(),
        optional(:showActions) =&gt; %{
          optional(:duration) =&gt; number(),
          optional(:position) =&gt; String.t(),
          optional(:fontSize) =&gt; integer(),
          optional(:cursor) =&gt; String.t(),
          optional(:style) =&gt; %{
            optional(:point) =&gt; String.t(),
            optional(:highlight) =&gt; String.t(),
            optional(:title) =&gt; String.t()
          }
        }
      },
      optional(:reduced_motion) =&gt; :null | :reduce | :no_preference,
      optional(:screen) =&gt; %{width: integer(), height: integer()},
      optional(:service_workers) =&gt; :allow | :block,
      optional(:storage_state) =&gt; String.t() | map(),
      optional(:strict_selectors) =&gt; boolean(),
      optional(:timezone_id) =&gt; String.t(),
      optional(:user_agent) =&gt; String.t(),
      optional(:viewport) =&gt; :null | %{width: integer(), height: integer()},
      optional(:default_browser_type) =&gt; String.t()
    }
```

Options of `new_context/2`, see its docs.

# `new_page_options`

```elixir
@type new_page_options() ::
  [
    accept_downloads: boolean(),
    base_url: String.t(),
    bypass_csp: boolean(),
    client_certificates: [
      %{
        :origin =&gt; String.t(),
        optional(:certPath) =&gt; String.t(),
        optional(:cert) =&gt; binary(),
        optional(:keyPath) =&gt; String.t(),
        optional(:key) =&gt; binary(),
        optional(:pfxPath) =&gt; String.t(),
        optional(:pfx) =&gt; binary(),
        optional(:passphrase) =&gt; String.t()
      }
    ],
    color_scheme: :null | :light | :dark | :no_preference,
    contrast: :null | :no_preference | :more,
    device_scale_factor: number(),
    extra_http_headers: %{optional(String.t()) =&gt; String.t()},
    forced_colors: :null | :active | :none,
    geolocation: %{
      :latitude =&gt; number(),
      :longitude =&gt; number(),
      optional(:accuracy) =&gt; number()
    },
    has_touch: boolean(),
    http_credentials:
      %{
        :username =&gt; String.t(),
        :password =&gt; String.t(),
        optional(:origin) =&gt; String.t(),
        optional(:send) =&gt; String.t()
      }
      | [
          %{
            :username =&gt; String.t(),
            :password =&gt; String.t(),
            optional(:origin) =&gt; String.t(),
            optional(:send) =&gt; String.t()
          }
        ],
    ignore_https_errors: boolean(),
    is_mobile: boolean(),
    java_script_enabled: boolean(),
    locale: String.t(),
    logger: %{
      isEnabled: (String.t(), String.t() -&gt; boolean()),
      log: (String.t(),
            String.t(),
            String.t()
            | Exception.t(),
            [map()],
            %{optional(:color) =&gt; String.t()} -&gt;
              term())
    },
    offline: boolean(),
    permissions: [String.t()],
    proxy: %{
      :server =&gt; String.t(),
      optional(:bypass) =&gt; String.t(),
      optional(:username) =&gt; String.t(),
      optional(:password) =&gt; String.t()
    },
    record_har: %{
      optional(:omitContent) =&gt; boolean(),
      optional(:content) =&gt; String.t(),
      :path =&gt; String.t(),
      optional(:mode) =&gt; String.t(),
      optional(:urlFilter) =&gt; String.t() | Regex.t() | Playwright.RegExp.t()
    },
    record_video: %{
      optional(:dir) =&gt; String.t(),
      optional(:size) =&gt; %{width: integer(), height: integer()},
      optional(:fps) =&gt; integer(),
      optional(:showActions) =&gt; %{
        optional(:duration) =&gt; number(),
        optional(:position) =&gt; String.t(),
        optional(:fontSize) =&gt; integer(),
        optional(:cursor) =&gt; String.t(),
        optional(:style) =&gt; %{
          optional(:point) =&gt; String.t(),
          optional(:highlight) =&gt; String.t(),
          optional(:title) =&gt; String.t()
        }
      }
    },
    reduced_motion: :null | :reduce | :no_preference,
    screen: %{width: integer(), height: integer()},
    service_workers: :allow | :block,
    storage_state: String.t() | map(),
    strict_selectors: boolean(),
    timezone_id: String.t(),
    user_agent: String.t(),
    viewport: :null | %{width: integer(), height: integer()},
    default_browser_type: String.t()
  ]
  | %{
      optional(:accept_downloads) =&gt; boolean(),
      optional(:base_url) =&gt; String.t(),
      optional(:bypass_csp) =&gt; boolean(),
      optional(:client_certificates) =&gt; [
        %{
          :origin =&gt; String.t(),
          optional(:certPath) =&gt; String.t(),
          optional(:cert) =&gt; binary(),
          optional(:keyPath) =&gt; String.t(),
          optional(:key) =&gt; binary(),
          optional(:pfxPath) =&gt; String.t(),
          optional(:pfx) =&gt; binary(),
          optional(:passphrase) =&gt; String.t()
        }
      ],
      optional(:color_scheme) =&gt; :null | :light | :dark | :no_preference,
      optional(:contrast) =&gt; :null | :no_preference | :more,
      optional(:device_scale_factor) =&gt; number(),
      optional(:extra_http_headers) =&gt; %{optional(String.t()) =&gt; String.t()},
      optional(:forced_colors) =&gt; :null | :active | :none,
      optional(:geolocation) =&gt; %{
        :latitude =&gt; number(),
        :longitude =&gt; number(),
        optional(:accuracy) =&gt; number()
      },
      optional(:has_touch) =&gt; boolean(),
      optional(:http_credentials) =&gt;
        %{
          :username =&gt; String.t(),
          :password =&gt; String.t(),
          optional(:origin) =&gt; String.t(),
          optional(:send) =&gt; String.t()
        }
        | [
            %{
              :username =&gt; String.t(),
              :password =&gt; String.t(),
              optional(:origin) =&gt; String.t(),
              optional(:send) =&gt; String.t()
            }
          ],
      optional(:ignore_https_errors) =&gt; boolean(),
      optional(:is_mobile) =&gt; boolean(),
      optional(:java_script_enabled) =&gt; boolean(),
      optional(:locale) =&gt; String.t(),
      optional(:logger) =&gt; %{
        isEnabled: (String.t(), String.t() -&gt; boolean()),
        log: (String.t(),
              String.t(),
              String.t()
              | Exception.t(),
              [map()],
              %{optional(:color) =&gt; String.t()} -&gt;
                term())
      },
      optional(:offline) =&gt; boolean(),
      optional(:permissions) =&gt; [String.t()],
      optional(:proxy) =&gt; %{
        :server =&gt; String.t(),
        optional(:bypass) =&gt; String.t(),
        optional(:username) =&gt; String.t(),
        optional(:password) =&gt; String.t()
      },
      optional(:record_har) =&gt; %{
        optional(:omitContent) =&gt; boolean(),
        optional(:content) =&gt; String.t(),
        :path =&gt; String.t(),
        optional(:mode) =&gt; String.t(),
        optional(:urlFilter) =&gt; String.t() | Regex.t() | Playwright.RegExp.t()
      },
      optional(:record_video) =&gt; %{
        optional(:dir) =&gt; String.t(),
        optional(:size) =&gt; %{width: integer(), height: integer()},
        optional(:fps) =&gt; integer(),
        optional(:showActions) =&gt; %{
          optional(:duration) =&gt; number(),
          optional(:position) =&gt; String.t(),
          optional(:fontSize) =&gt; integer(),
          optional(:cursor) =&gt; String.t(),
          optional(:style) =&gt; %{
            optional(:point) =&gt; String.t(),
            optional(:highlight) =&gt; String.t(),
            optional(:title) =&gt; String.t()
          }
        }
      },
      optional(:reduced_motion) =&gt; :null | :reduce | :no_preference,
      optional(:screen) =&gt; %{width: integer(), height: integer()},
      optional(:service_workers) =&gt; :allow | :block,
      optional(:storage_state) =&gt; String.t() | map(),
      optional(:strict_selectors) =&gt; boolean(),
      optional(:timezone_id) =&gt; String.t(),
      optional(:user_agent) =&gt; String.t(),
      optional(:viewport) =&gt; :null | %{width: integer(), height: integer()},
      optional(:default_browser_type) =&gt; String.t()
    }
```

Options of `new_page/2`, see its docs.

# `remove_all_listeners_options`

```elixir
@type remove_all_listeners_options() ::
  [{:behavior, :wait | :ignore_errors | :default}]
  | %{optional(:behavior) =&gt; :wait | :ignore_errors | :default}
```

Options of `remove_all_listeners/3`, see its docs.

# `start_tracing_options`

```elixir
@type start_tracing_options() ::
  [categories: [String.t()], path: String.t(), screenshots: boolean()]
  | %{
      optional(:categories) =&gt; [String.t()],
      optional(:path) =&gt; String.t(),
      optional(:screenshots) =&gt; boolean()
    }
```

Options of `start_tracing/3`, see its docs.

# `t`

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

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

# `bind`

```elixir
@spec bind(t(), String.t(), bind_options()) ::
  {:ok, %{endpoint: String.t()}} | {:error, Playwright.error()}
```

Binds the browser to a named pipe or web socket, making it available for other clients to connect to.

*Since Playwright 1.59.*

## Arguments

* `title` - Title of the browser server, used for identification.

## Options

* `:host` (`t:String.t/0`) - Host to bind the web socket server to. When specified, a web socket server is created instead of a named pipe.
* `:metadata` (`%{optional(String.t()) => term()}`) - Additional metadata to associate with the browser server.
* `:port` (`t:integer/0`) - Port to bind the web socket server to. When specified, a web socket server is created instead of a named pipe. Use `0` to let the OS pick an available port.
* `:workspace_dir` (`t:String.t/0`) - Working directory associated with this browser server.

# `bind!`

```elixir
@spec bind!(t(), String.t(), bind_options()) :: %{endpoint: String.t()}
```

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

# `browser_type`

```elixir
@spec browser_type(t()) :: Playwright.BrowserType.t()
```

Get the browser type (chromium, firefox or webkit) that the browser belongs to.

*Since Playwright 1.23.*

# `close`

```elixir
@spec close(t(), close_options()) :: :ok | {:error, Playwright.error()}
```

In case this browser is obtained using `Playwright.BrowserType.launch/2`, closes the browser and all of its pages (if any
were opened).

In case this browser is connected to, clears all created contexts belonging to this browser and disconnects from the
browser server.

> #### Note {: .info}
>
> This is similar to force-quitting the browser. To close pages gracefully and ensure you receive page close events, call `Playwright.BrowserContext.close/2` on any [`BrowserContext`](`Playwright.BrowserContext`) instances you explicitly created earlier using `Playwright.Browser.new_context/2` **before** calling `Playwright.Browser.close/2`.

The [`Browser`](`Playwright.Browser`) object itself is considered to be disposed and cannot be used anymore.

*Since Playwright 1.8.*

## Options

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

# `close!`

```elixir
@spec close!(t(), close_options()) :: :ok
```

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

# `contexts`

```elixir
@spec contexts(t()) :: [Playwright.BrowserContext.t()]
```

Returns an array of all open browser contexts. In a newly created browser, this will return zero browser contexts.

**Usage**

```elixir
browser = BrowserType.launch!(Playwright.webkit(playwright))
# prints 0
IO.puts(length(Browser.contexts(browser)))

context = Browser.new_context!(browser)
# prints 1
IO.puts(length(Browser.contexts(browser)))
```

*Since Playwright 1.8.*

# `is_connected`

```elixir
@spec is_connected(t()) :: boolean()
```

Indicates that the browser is connected.

*Since Playwright 1.8.*

# `new_browser_cdp_session`

```elixir
@spec new_browser_cdp_session(t()) ::
  {:ok, Playwright.CDPSession.t()} | {:error, Playwright.error()}
```

> #### Note {: .info}
>
> CDP Sessions are only supported on Chromium-based browsers.

Returns the newly created browser session.

*Since Playwright 1.11.*

# `new_browser_cdp_session!`

```elixir
@spec new_browser_cdp_session!(t()) :: Playwright.CDPSession.t()
```

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

# `new_context`

```elixir
@spec new_context(t(), new_context_options()) ::
  {:ok, Playwright.BrowserContext.t()} | {:error, Playwright.error()}
```

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

> #### Note {: .info}
>
> If directly using this method to create [`BrowserContext`](`Playwright.BrowserContext`)s, it is best practice to explicitly close the returned context via `Playwright.BrowserContext.close/2` when your code is done with the [`BrowserContext`](`Playwright.BrowserContext`),
> and before calling `Playwright.Browser.close/2`. This will ensure the `context` is closed gracefully and any artifacts—like HARs and videos—are fully flushed and saved.

**Usage**

```elixir
# Or Playwright.chromium/1 or Playwright.webkit/1.
browser = BrowserType.launch!(Playwright.firefox(playwright))
# Create a new incognito browser context.
context = Browser.new_context!(browser)
# Create a new page in a pristine context.
page = BrowserContext.new_page!(context)
Page.goto!(page, "https://example.com")

# Gracefully close up everything
BrowserContext.close!(context)
Browser.close!(browser)
```

*Since Playwright 1.8.*

## Options

* `:accept_downloads` (`t:boolean/0`) - Whether to automatically download all the attachments. Defaults to `true` where all the downloads are accepted.
* `:base_url` (`t:String.t/0`) - When using `Playwright.Page.goto/3`, `Playwright.Page.route/4`, `Playwright.Page.wait_for_url/3`, `Playwright.Page.wait_for_request/3`, or `Playwright.Page.wait_for_response/3` it takes the base URL in consideration by using the [`URL()`](https://developer.mozilla.org/en-US/docs/Web/API/URL/URL) constructor for building the corresponding URL. Unset by default. Examples:

  * baseURL: `http://localhost:3000` and navigating to `/bar.html` results in `http://localhost:3000/bar.html`
  * baseURL: `http://localhost:3000/foo/` and navigating to `./bar.html` results in `http://localhost:3000/foo/bar.html`
  * baseURL: `http://localhost:3000/foo` (without trailing slash) and navigating to `./bar.html` results in `http://localhost:3000/bar.html`
* `:bypass_csp` (`t:boolean/0`) - Toggles bypassing page's Content-Security-Policy. Defaults to `false`.
* `:client_certificates` (list of `t:map/0`) - *Since Playwright 1.46.* TLS Client Authentication allows the server to request a client certificate and verify it.

  **Details**

  An array of client certificates to be used. Each certificate object must have either both `certPath` and `keyPath`, a single `pfxPath`, or their corresponding direct value equivalents (`cert` and `key`, or `pfx`). Optionally, `passphrase` property should be provided if the certificate is encrypted. The `origin` property should be provided with an exact match to the request origin that the certificate is valid for.

  Client certificate authentication is only active when at least one client certificate is provided. If you want to reject all client certificates sent by the server, you need to provide a client certificate with an `origin` that does not match any of the domains you plan to visit.

  > #### Note {: .info}
  >
  > When using WebKit on macOS, accessing `localhost` will not pick up client certificates. You can make it work by replacing `localhost` with `local.playwright`.

  * `:origin` - Exact origin that the certificate is valid for. Origin includes `https` protocol, a hostname and optionally a port.
  * `:certPath` - Path to the file with the certificate in PEM format.
  * `:cert` - Direct value of the certificate in PEM format.
  * `:keyPath` - Path to the file with the private key in PEM format.
  * `:key` - Direct value of the private key in PEM format.
  * `:pfxPath` - Path to the PFX or PKCS12 encoded private key and certificate chain.
  * `:pfx` - Direct value of the PFX or PKCS12 encoded private key and certificate chain.
  * `:passphrase` - Passphrase for the private key (PEM or PFX).
* `:color_scheme` (`:null` | `:light` | `:dark` | `:no_preference`) - Emulates [prefers-colors-scheme](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme) media feature, supported values are `:light` and `:dark`. See
  `Playwright.Page.emulate_media/2` for more details. Passing `:null` resets emulation to system defaults. Defaults to `:light`.
* `:contrast` (`:null` | `:no_preference` | `:more`) - Emulates `'prefers-contrast'` media feature, supported values are `:no_preference`, `:more`. See `Playwright.Page.emulate_media/2` for more details. Passing `:null` resets emulation to system defaults. Defaults to `:no_preference`.
* `:device_scale_factor` (`t:number/0`) - Specify device scale factor (can be thought of as dpr). Defaults to `1`. Learn more about [emulating devices with device scale factor](https://playwright.dev/docs/emulation#devices).
* `:extra_http_headers` (`%{optional(String.t()) => String.t()}`) - An object containing additional HTTP headers to be sent with every request. Defaults to none.
* `:forced_colors` (`:null` | `:active` | `:none`) - Emulates `'forced-colors'` media feature, supported values are `:active`, `:none`. See `Playwright.Page.emulate_media/2` for more details. Passing `:null` resets emulation to system defaults. Defaults to `:none`.
* `:geolocation` (`t:map/0`)
  * `:latitude` - Latitude between -90 and 90.
  * `:longitude` - Longitude between -180 and 180.
  * `:accuracy` - Non-negative accuracy value. Defaults to `0`.
* `:has_touch` (`t:boolean/0`) - Specifies if viewport supports touch events. Defaults to false. Learn more about [mobile emulation](https://playwright.dev/docs/emulation#devices).
* `:http_credentials` (`t:map/0` | list of `t:map/0`) - Credentials for [HTTP authentication](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication).
  If no origin is specified, the username and password are sent to any servers upon unauthorized responses.

  Pass an array to use different credentials for different origins. The first entry that matches the request origin is used, and entries with no origin match any request.

  * `:username`
  * `:password`
  * `:origin` - Restrain sending http credentials on specific origin (scheme://host:port).
  * `:send` - This option only applies to the requests sent from corresponding [`APIRequestContext`](`Playwright.APIRequestContext`) and does not affect requests sent from the browser. `'always'` - `Authorization` header with basic authentication credentials will be sent with the each API request. `'unauthorized` - the credentials are only sent when 401 (Unauthorized) response with `WWW-Authenticate` header is received. Defaults to `'unauthorized'`.
* `: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. isMobile is a part of device, so you don't actually need to set it manually. Defaults to `false`. Learn more about [mobile emulation](https://playwright.dev/docs/emulation#ismobile).
* `:java_script_enabled` (`t:boolean/0`) - Whether or not to enable JavaScript in the context. Defaults to `true`. Learn more about [disabling JavaScript](https://playwright.dev/docs/emulation#javascript-enabled).
* `:locale` (`t:String.t/0`) - Specify user locale, for example `en-GB`, `de-DE`, etc. Locale will affect `navigator.language` value, `Accept-Language` request header value as well as number and date formatting rules. Defaults to the system default locale. Learn more about emulation in our [emulation guide](https://playwright.dev/docs/emulation#locale--timezone).
* `:logger` (`t:map/0`) - Logger sink for Playwright logging.
  * `:isEnabled` - Determines whether sink is interested in the logger with the given name and severity.
  * `:log`
* `:offline` (`t:boolean/0`) - Whether to emulate network being offline. Defaults to `false`. Learn more about [network emulation](https://playwright.dev/docs/emulation#offline).
* `:permissions` (list of `t:String.t/0`) - A list of permissions to grant to all pages in this context. See
  `Playwright.BrowserContext.grant_permissions/3` for more details. Defaults to none.
* `:proxy` (`t:map/0`) - Network proxy settings to use with this context. Defaults to none.
  * `:server` - Proxy to be used for all requests. HTTP and SOCKS proxies are supported, for example
    `http://myproxy.com:3128` or `socks5://myproxy.com:3128`. Short form `myproxy.com:3128` is considered an HTTP proxy.
  * `:bypass` - Optional comma-separated domains to bypass proxy, for example `".com, chromium.org, .domain.com"`.
  * `:username` - Optional username to use if HTTP proxy requires authentication.
  * `:password` - Optional password to use if HTTP proxy requires authentication.
* `:record_har` (`t:map/0`) - Enables [HAR](http://www.softwareishard.com/blog/har-12-spec) recording for all pages into `recordHar.path` file. If not
  specified, the HAR is not recorded. Make sure to call `Playwright.BrowserContext.close/2` for the HAR to be
  saved.
  * `:omitContent` - Optional setting to control whether to omit request content from the HAR. Defaults to
    `false`. Deprecated, use `content` policy instead.
  * `:content` - Optional setting to control resource content management. If `omit` is specified, content is not persisted. If `attach` is specified, resources are persisted as separate files or entries in the ZIP archive. If `embed` is specified, content is stored inline the HAR file as per HAR specification. Defaults to `attach` for `.zip` output files and to `embed` for all other file extensions.
  * `:path` - Path on the filesystem to write the HAR file to. If the file name ends with `.zip`, `content: 'attach'` is used by default.
  * `:mode` - When set to `minimal`, only record information necessary for routing from HAR. This omits sizes, timing, page, cookies, security and other types of HAR information that are not used when replaying from HAR. Defaults to `full`.
  * `:urlFilter` - A glob or regex pattern to filter requests that are stored in the HAR. When a `:base_url` via the context options was provided and the passed URL is a path, it gets merged via the [`new URL()`](https://developer.mozilla.org/en-US/docs/Web/API/URL/URL) constructor. Defaults to none.
* `:record_video` (`t:map/0`) - Enables video recording for all pages into `recordVideo.dir` directory. If not specified videos are not recorded. Make
  sure to call `Playwright.BrowserContext.close/2` for videos to be saved.
  * `:dir` - Path to the directory to put videos into. If not specified, the videos will be stored in `:artifacts_dir` (see `Playwright.BrowserType.launch/2` options).
  * `:size` - Optional dimensions of the recorded videos. If not specified the size will be equal to `:viewport`
    scaled down to fit into 800x800. If `:viewport` is not configured explicitly the video size defaults to 800x450.
    Actual picture of each page will be scaled down if necessary to fit the specified size.
    * `:width` - Video frame width.
    * `:height` - Video frame height.
  * `:fps` - Frame rate of the recorded videos in frames per second. Defaults to `25`. Firefox and WebKit currently capture up to 25 frames per second.
  * `:showActions` - If specified, enables visual annotations on interacted elements during video recording.
    * `:duration` - How long each annotation is displayed in milliseconds. Defaults to `500`.
    * `:position` - Position of the action title overlay. Defaults to `"top-right"`.
    * `:fontSize` - Font size of the action title in pixels. Defaults to `24`. Deprecated, use `style.title` instead.
    * `:cursor` - 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.
    * `:style` - Styles of the action decorations.
      * `:point` - CSS declarations for the zero-sized marker centered on the action point. Not shown when omitted.
      * `:highlight` - CSS declarations for the box that covers the target element. Not shown when omitted.
      * `:title` - CSS declarations for the action title.
* `:reduced_motion` (`:null` | `:reduce` | `:no_preference`) - Emulates `'prefers-reduced-motion'` media feature, supported values are `:reduce`, `:no_preference`. See `Playwright.Page.emulate_media/2` for more details. Passing `:null` resets emulation to system defaults. Defaults to `:no_preference`.
* `:screen` (`t:map/0`) - Emulates consistent window screen size available inside web page via `window.screen`. Is only used when the
  `:viewport` is set.
  * `:width` - page width in pixels.
  * `:height` - page height in pixels.
* `:service_workers` (`:allow` | `:block`) - Whether to allow sites to register Service workers. Defaults to `:allow`.

  * `:allow`: [Service Workers](https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API) can be registered.
  * `:block`: Playwright will block all registration of Service Workers.
* `:storage_state` (`t:String.t/0` | `t:map/0`) - Learn more about [storage state and auth](https://playwright.dev/docs/auth).

  Populates context with given storage state. This option can be used to initialize context with logged-in information obtained via `Playwright.BrowserContext.storage_state/2`.

  * `:cookies` - Cookies to set for context
    * `:name`
    * `:value`
    * `:domain` - Domain and path are required. For the cookie to apply to all subdomains as well, prefix domain with a dot, like this: ".example.com"
    * `:path` - Domain and path are required
    * `:expires` - Unix time in seconds.
    * `:httpOnly`
    * `:secure`
    * `:sameSite` - sameSite flag
  * `:origins`
    * `:origin`
    * `:localStorage` - localStorage to set for context
      * `:name`
      * `:value`
* `:strict_selectors` (`t:boolean/0`) - If set to true, enables strict selectors mode for this context. In the strict selectors mode all operations
  on selectors that imply single target DOM element will fail when more than one element matches the selector.
  This option does not affect any Locator APIs (Locators are always strict). Defaults to `false`.
  See [`Locator`](`Playwright.Locator`) to learn more about the strict mode.
* `:timezone_id` (`t:String.t/0`) - Changes the timezone of the context. See [ICU's metaZones.txt](https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1)
  for a list of supported timezone IDs. Defaults to the system timezone.
* `:user_agent` (`t:String.t/0`) - Specific user agent to use in this context.
* `:viewport` (`:null` | `t:map/0`) - Emulates consistent viewport for each page. Defaults to an 1280x720 viewport.
  Use `:null` to disable the consistent viewport emulation. Learn more about [viewport emulation](https://playwright.dev/docs/emulation#viewport).

  > #### Note {: .info}
  >
  > The `:null` value opts out from the default presets, makes viewport depend on the
  > host window size defined by the operating system. It makes the execution of the
  > tests non-deterministic.

  * `:width` - page width in pixels.
  * `:height` - page height in pixels.
* `:default_browser_type` (`t:String.t/0`) - Ignored: the browser type of a device descriptor (`Playwright.devices/1`), so one can be passed as options.

# `new_context!`

```elixir
@spec new_context!(t(), new_context_options()) :: Playwright.BrowserContext.t()
```

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

# `new_page`

```elixir
@spec new_page(t(), new_page_options()) ::
  {:ok, Playwright.Page.t()} | {:error, Playwright.error()}
```

Creates a new page in a new browser context. Closing this page will close the context as well.

This is a convenience API that should only be used for the single-page scenarios and short snippets. Production code and
testing frameworks should explicitly create `Playwright.Browser.new_context/2` followed by the
`Playwright.BrowserContext.new_page/1` to control their exact life times.

*Since Playwright 1.8.*

## Options

* `:accept_downloads` (`t:boolean/0`) - Whether to automatically download all the attachments. Defaults to `true` where all the downloads are accepted.
* `:base_url` (`t:String.t/0`) - When using `Playwright.Page.goto/3`, `Playwright.Page.route/4`, `Playwright.Page.wait_for_url/3`, `Playwright.Page.wait_for_request/3`, or `Playwright.Page.wait_for_response/3` it takes the base URL in consideration by using the [`URL()`](https://developer.mozilla.org/en-US/docs/Web/API/URL/URL) constructor for building the corresponding URL. Unset by default. Examples:

  * baseURL: `http://localhost:3000` and navigating to `/bar.html` results in `http://localhost:3000/bar.html`
  * baseURL: `http://localhost:3000/foo/` and navigating to `./bar.html` results in `http://localhost:3000/foo/bar.html`
  * baseURL: `http://localhost:3000/foo` (without trailing slash) and navigating to `./bar.html` results in `http://localhost:3000/bar.html`
* `:bypass_csp` (`t:boolean/0`) - Toggles bypassing page's Content-Security-Policy. Defaults to `false`.
* `:client_certificates` (list of `t:map/0`) - *Since Playwright 1.46.* TLS Client Authentication allows the server to request a client certificate and verify it.

  **Details**

  An array of client certificates to be used. Each certificate object must have either both `certPath` and `keyPath`, a single `pfxPath`, or their corresponding direct value equivalents (`cert` and `key`, or `pfx`). Optionally, `passphrase` property should be provided if the certificate is encrypted. The `origin` property should be provided with an exact match to the request origin that the certificate is valid for.

  Client certificate authentication is only active when at least one client certificate is provided. If you want to reject all client certificates sent by the server, you need to provide a client certificate with an `origin` that does not match any of the domains you plan to visit.

  > #### Note {: .info}
  >
  > When using WebKit on macOS, accessing `localhost` will not pick up client certificates. You can make it work by replacing `localhost` with `local.playwright`.

  * `:origin` - Exact origin that the certificate is valid for. Origin includes `https` protocol, a hostname and optionally a port.
  * `:certPath` - Path to the file with the certificate in PEM format.
  * `:cert` - Direct value of the certificate in PEM format.
  * `:keyPath` - Path to the file with the private key in PEM format.
  * `:key` - Direct value of the private key in PEM format.
  * `:pfxPath` - Path to the PFX or PKCS12 encoded private key and certificate chain.
  * `:pfx` - Direct value of the PFX or PKCS12 encoded private key and certificate chain.
  * `:passphrase` - Passphrase for the private key (PEM or PFX).
* `:color_scheme` (`:null` | `:light` | `:dark` | `:no_preference`) - Emulates [prefers-colors-scheme](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme) media feature, supported values are `:light` and `:dark`. See
  `Playwright.Page.emulate_media/2` for more details. Passing `:null` resets emulation to system defaults. Defaults to `:light`.
* `:contrast` (`:null` | `:no_preference` | `:more`) - Emulates `'prefers-contrast'` media feature, supported values are `:no_preference`, `:more`. See `Playwright.Page.emulate_media/2` for more details. Passing `:null` resets emulation to system defaults. Defaults to `:no_preference`.
* `:device_scale_factor` (`t:number/0`) - Specify device scale factor (can be thought of as dpr). Defaults to `1`. Learn more about [emulating devices with device scale factor](https://playwright.dev/docs/emulation#devices).
* `:extra_http_headers` (`%{optional(String.t()) => String.t()}`) - An object containing additional HTTP headers to be sent with every request. Defaults to none.
* `:forced_colors` (`:null` | `:active` | `:none`) - Emulates `'forced-colors'` media feature, supported values are `:active`, `:none`. See `Playwright.Page.emulate_media/2` for more details. Passing `:null` resets emulation to system defaults. Defaults to `:none`.
* `:geolocation` (`t:map/0`)
  * `:latitude` - Latitude between -90 and 90.
  * `:longitude` - Longitude between -180 and 180.
  * `:accuracy` - Non-negative accuracy value. Defaults to `0`.
* `:has_touch` (`t:boolean/0`) - Specifies if viewport supports touch events. Defaults to false. Learn more about [mobile emulation](https://playwright.dev/docs/emulation#devices).
* `:http_credentials` (`t:map/0` | list of `t:map/0`) - Credentials for [HTTP authentication](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication).
  If no origin is specified, the username and password are sent to any servers upon unauthorized responses.

  Pass an array to use different credentials for different origins. The first entry that matches the request origin is used, and entries with no origin match any request.

  * `:username`
  * `:password`
  * `:origin` - Restrain sending http credentials on specific origin (scheme://host:port).
  * `:send` - This option only applies to the requests sent from corresponding [`APIRequestContext`](`Playwright.APIRequestContext`) and does not affect requests sent from the browser. `'always'` - `Authorization` header with basic authentication credentials will be sent with the each API request. `'unauthorized` - the credentials are only sent when 401 (Unauthorized) response with `WWW-Authenticate` header is received. Defaults to `'unauthorized'`.
* `: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. isMobile is a part of device, so you don't actually need to set it manually. Defaults to `false`. Learn more about [mobile emulation](https://playwright.dev/docs/emulation#ismobile).
* `:java_script_enabled` (`t:boolean/0`) - Whether or not to enable JavaScript in the context. Defaults to `true`. Learn more about [disabling JavaScript](https://playwright.dev/docs/emulation#javascript-enabled).
* `:locale` (`t:String.t/0`) - Specify user locale, for example `en-GB`, `de-DE`, etc. Locale will affect `navigator.language` value, `Accept-Language` request header value as well as number and date formatting rules. Defaults to the system default locale. Learn more about emulation in our [emulation guide](https://playwright.dev/docs/emulation#locale--timezone).
* `:logger` (`t:map/0`) - Logger sink for Playwright logging.
  * `:isEnabled` - Determines whether sink is interested in the logger with the given name and severity.
  * `:log`
* `:offline` (`t:boolean/0`) - Whether to emulate network being offline. Defaults to `false`. Learn more about [network emulation](https://playwright.dev/docs/emulation#offline).
* `:permissions` (list of `t:String.t/0`) - A list of permissions to grant to all pages in this context. See
  `Playwright.BrowserContext.grant_permissions/3` for more details. Defaults to none.
* `:proxy` (`t:map/0`) - Network proxy settings to use with this context. Defaults to none.
  * `:server` - Proxy to be used for all requests. HTTP and SOCKS proxies are supported, for example
    `http://myproxy.com:3128` or `socks5://myproxy.com:3128`. Short form `myproxy.com:3128` is considered an HTTP proxy.
  * `:bypass` - Optional comma-separated domains to bypass proxy, for example `".com, chromium.org, .domain.com"`.
  * `:username` - Optional username to use if HTTP proxy requires authentication.
  * `:password` - Optional password to use if HTTP proxy requires authentication.
* `:record_har` (`t:map/0`) - Enables [HAR](http://www.softwareishard.com/blog/har-12-spec) recording for all pages into `recordHar.path` file. If not
  specified, the HAR is not recorded. Make sure to call `Playwright.BrowserContext.close/2` for the HAR to be
  saved.
  * `:omitContent` - Optional setting to control whether to omit request content from the HAR. Defaults to
    `false`. Deprecated, use `content` policy instead.
  * `:content` - Optional setting to control resource content management. If `omit` is specified, content is not persisted. If `attach` is specified, resources are persisted as separate files or entries in the ZIP archive. If `embed` is specified, content is stored inline the HAR file as per HAR specification. Defaults to `attach` for `.zip` output files and to `embed` for all other file extensions.
  * `:path` - Path on the filesystem to write the HAR file to. If the file name ends with `.zip`, `content: 'attach'` is used by default.
  * `:mode` - When set to `minimal`, only record information necessary for routing from HAR. This omits sizes, timing, page, cookies, security and other types of HAR information that are not used when replaying from HAR. Defaults to `full`.
  * `:urlFilter` - A glob or regex pattern to filter requests that are stored in the HAR. When a `:base_url` via the context options was provided and the passed URL is a path, it gets merged via the [`new URL()`](https://developer.mozilla.org/en-US/docs/Web/API/URL/URL) constructor. Defaults to none.
* `:record_video` (`t:map/0`) - Enables video recording for all pages into `recordVideo.dir` directory. If not specified videos are not recorded. Make
  sure to call `Playwright.BrowserContext.close/2` for videos to be saved.
  * `:dir` - Path to the directory to put videos into. If not specified, the videos will be stored in `:artifacts_dir` (see `Playwright.BrowserType.launch/2` options).
  * `:size` - Optional dimensions of the recorded videos. If not specified the size will be equal to `:viewport`
    scaled down to fit into 800x800. If `:viewport` is not configured explicitly the video size defaults to 800x450.
    Actual picture of each page will be scaled down if necessary to fit the specified size.
    * `:width` - Video frame width.
    * `:height` - Video frame height.
  * `:fps` - Frame rate of the recorded videos in frames per second. Defaults to `25`. Firefox and WebKit currently capture up to 25 frames per second.
  * `:showActions` - If specified, enables visual annotations on interacted elements during video recording.
    * `:duration` - How long each annotation is displayed in milliseconds. Defaults to `500`.
    * `:position` - Position of the action title overlay. Defaults to `"top-right"`.
    * `:fontSize` - Font size of the action title in pixels. Defaults to `24`. Deprecated, use `style.title` instead.
    * `:cursor` - 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.
    * `:style` - Styles of the action decorations.
      * `:point` - CSS declarations for the zero-sized marker centered on the action point. Not shown when omitted.
      * `:highlight` - CSS declarations for the box that covers the target element. Not shown when omitted.
      * `:title` - CSS declarations for the action title.
* `:reduced_motion` (`:null` | `:reduce` | `:no_preference`) - Emulates `'prefers-reduced-motion'` media feature, supported values are `:reduce`, `:no_preference`. See `Playwright.Page.emulate_media/2` for more details. Passing `:null` resets emulation to system defaults. Defaults to `:no_preference`.
* `:screen` (`t:map/0`) - Emulates consistent window screen size available inside web page via `window.screen`. Is only used when the
  `:viewport` is set.
  * `:width` - page width in pixels.
  * `:height` - page height in pixels.
* `:service_workers` (`:allow` | `:block`) - Whether to allow sites to register Service workers. Defaults to `:allow`.

  * `:allow`: [Service Workers](https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API) can be registered.
  * `:block`: Playwright will block all registration of Service Workers.
* `:storage_state` (`t:String.t/0` | `t:map/0`) - Learn more about [storage state and auth](https://playwright.dev/docs/auth).

  Populates context with given storage state. This option can be used to initialize context with logged-in information obtained via `Playwright.BrowserContext.storage_state/2`.

  * `:cookies` - Cookies to set for context
    * `:name`
    * `:value`
    * `:domain` - Domain and path are required. For the cookie to apply to all subdomains as well, prefix domain with a dot, like this: ".example.com"
    * `:path` - Domain and path are required
    * `:expires` - Unix time in seconds.
    * `:httpOnly`
    * `:secure`
    * `:sameSite` - sameSite flag
  * `:origins`
    * `:origin`
    * `:localStorage` - localStorage to set for context
      * `:name`
      * `:value`
* `:strict_selectors` (`t:boolean/0`) - If set to true, enables strict selectors mode for this context. In the strict selectors mode all operations
  on selectors that imply single target DOM element will fail when more than one element matches the selector.
  This option does not affect any Locator APIs (Locators are always strict). Defaults to `false`.
  See [`Locator`](`Playwright.Locator`) to learn more about the strict mode.
* `:timezone_id` (`t:String.t/0`) - Changes the timezone of the context. See [ICU's metaZones.txt](https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1)
  for a list of supported timezone IDs. Defaults to the system timezone.
* `:user_agent` (`t:String.t/0`) - Specific user agent to use in this context.
* `:viewport` (`:null` | `t:map/0`) - Emulates consistent viewport for each page. Defaults to an 1280x720 viewport.
  Use `:null` to disable the consistent viewport emulation. Learn more about [viewport emulation](https://playwright.dev/docs/emulation#viewport).

  > #### Note {: .info}
  >
  > The `:null` value opts out from the default presets, makes viewport depend on the
  > host window size defined by the operating system. It makes the execution of the
  > tests non-deterministic.

  * `:width` - page width in pixels.
  * `:height` - page height in pixels.
* `:default_browser_type` (`t:String.t/0`) - Ignored: the browser type of a device descriptor (`Playwright.devices/1`), so one can be passed as options.

# `new_page!`

```elixir
@spec new_page!(t(), new_page_options()) :: Playwright.Page.t()
```

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

# `remove_all_listeners`

```elixir
@spec remove_all_listeners(
  t(),
  event() | String.t() | nil,
  remove_all_listeners_options()
) ::
  :ok | {:error, Playwright.error()}
```

Removes all the listeners of the given type (or all registered listeners if no type given).
Allows to wait for running listeners to complete or to ignore subsequent errors from these listeners.

*Since Playwright 1.47.*

## Options

The options may take the place of `event`, which is then `nil`.

* `:behavior` (`:wait` | `:ignore_errors` | `:default`) - Specifies whether to wait for already running listeners and what to do if they raise:

  * `:default` - do not wait for current listener calls (if any) to finish, if the listener raises, it may result in unhandled error
  * `:wait` - wait for current listener calls (if any) to finish
  * `:ignore_errors` - do not wait for current listener calls (if any) to finish, all errors raised by the listeners after removal are silently caught

# `remove_all_listeners!`

```elixir
@spec remove_all_listeners!(
  t(),
  event() | String.t() | nil,
  remove_all_listeners_options()
) :: :ok
```

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

# `start_tracing`

```elixir
@spec start_tracing(t(), Playwright.Page.t() | nil, start_tracing_options()) ::
  :ok | {:error, Playwright.error()}
```

> #### Note {: .info}
>
> This API controls [Chromium Tracing](https://www.chromium.org/developers/how-tos/trace-event-profiling-tool) which is a low-level chromium-specific debugging tool. API to control [Playwright Tracing](https://playwright.dev/docs/trace-viewer) could be found [here](https://playwright.dev/docs/api/class-tracing).

You can use `Playwright.Browser.start_tracing/3` and `Playwright.Browser.stop_tracing/1` to create a trace file that can
be opened in Chrome DevTools performance panel.

**Usage**

```elixir
Browser.start_tracing!(browser, page, path: "trace.json")
Page.goto!(page, "https://www.google.com")
Browser.stop_tracing!(browser)
```

*Since Playwright 1.11.*

## Arguments

* `page` - Optional, if specified, tracing includes screenshots of the given page.

## Options

The options may take the place of `page`, which is then `nil`.

* `:categories` (list of `t:String.t/0`) - specify custom categories to use instead of default.
* `:path` (`t:String.t/0`) - A path to write the trace file to.
* `:screenshots` (`t:boolean/0`) - captures screenshots in the trace.

# `start_tracing!`

```elixir
@spec start_tracing!(t(), Playwright.Page.t() | nil, start_tracing_options()) :: :ok
```

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

# `stop_tracing`

```elixir
@spec stop_tracing(t()) :: {:ok, binary()} | {:error, Playwright.error()}
```

> #### Note {: .info}
>
> This API controls [Chromium Tracing](https://www.chromium.org/developers/how-tos/trace-event-profiling-tool) which is a low-level chromium-specific debugging tool. API to control [Playwright Tracing](https://playwright.dev/docs/trace-viewer) could be found [here](https://playwright.dev/docs/api/class-tracing).

Returns the buffer with trace data.

*Since Playwright 1.11.*

# `stop_tracing!`

```elixir
@spec stop_tracing!(t()) :: binary()
```

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

# `unbind`

```elixir
@spec unbind(t()) :: :ok | {:error, Playwright.error()}
```

Unbinds the browser server previously bound with `Playwright.Browser.bind/3`.

*Since Playwright 1.59.*

# `unbind!`

```elixir
@spec unbind!(t()) :: :ok
```

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

# `version`

```elixir
@spec version(t()) :: String.t()
```

Returns the browser version.

*Since Playwright 1.8.*

# `add_listener`

```elixir
@spec add_listener(t(), :context, (Playwright.BrowserContext.t() -&gt; term())) :: t()
@spec add_listener(t(), :disconnected, (t() -&gt; term())) :: t()
@spec add_listener(t(), String.t(), (term() -&gt; term())) :: t()
```

Adds an event listener for `event`, see the module docs for the events.

# `off`

```elixir
@spec off(t(), :context, (Playwright.BrowserContext.t() -&gt; term())) :: t()
@spec off(t(), :disconnected, (t() -&gt; term())) :: t()
@spec off(t(), String.t(), (term() -&gt; term())) :: t()
```

Removes an event listener added by `on/3` or `add_listener/3`.

# `on`

```elixir
@spec on(t(), :context, (Playwright.BrowserContext.t() -&gt; term())) :: t()
@spec on(t(), :disconnected, (t() -&gt; term())) :: t()
@spec on(t(), String.t(), (term() -&gt; term())) :: t()
```

Adds an event listener for `event`, see the module docs for the events.

# `once`

```elixir
@spec once(t(), :context, (Playwright.BrowserContext.t() -&gt; term())) :: t()
@spec once(t(), :disconnected, (t() -&gt; term())) :: t()
@spec once(t(), String.t(), (term() -&gt; term())) :: t()
```

Adds an event listener that is removed after it is triggered once. See `on/3`.

# `prepend_listener`

```elixir
@spec prepend_listener(t(), :context, (Playwright.BrowserContext.t() -&gt; term())) ::
  t()
@spec prepend_listener(t(), :disconnected, (t() -&gt; term())) :: t()
@spec prepend_listener(t(), String.t(), (term() -&gt; term())) :: t()
```

Adds an event listener for `event`, see the module docs for the events.

# `remove_listener`

```elixir
@spec remove_listener(t(), :context, (Playwright.BrowserContext.t() -&gt; term())) :: t()
@spec remove_listener(t(), :disconnected, (t() -&gt; term())) :: t()
@spec remove_listener(t(), String.t(), (term() -&gt; term())) :: t()
```

Removes an event listener added by `on/3` or `add_listener/3`.

---

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