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

A Playwright.Browser instance is createed via:

An example of using a Playwright.Browser to create a Playwright.Page:

alias Playwright.{Browser, Page}

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

Page.goto(page, "https://example.com")
Browser.close(browser)

Properties

  • :name
  • :version

Link to this section Summary

Types

Supported events

A map/struct providing call options

t()

%Playwright.Browser{}

Functions

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

Create a new Playwright.Page for this Browser, within a new "owned" Playwright.BrowserContext.

Link to this section Types

Specs

event() :: :disconnected

Supported events

Specs

options() :: map()

A map/struct providing call options

Specs

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

%Playwright.Browser{}

Link to this section Functions

Specs

contexts(t()) :: {:ok, [Playwright.BrowserContext.t()]}

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

Example

{:ok, contexts} = Browser.contexts(browser)
asset Enum.empty?(contexts)

Browser.new_context(browser)

{:ok, contexts} = Browser.contexts(browser)
assert length(contexts) == 1
Link to this function

new_context(owner, options \\ %{})

View Source

Specs

new_context(t(), options()) :: {:ok, Playwright.BrowserContext.t()}

Create a new Playwright.BrowserContext for this Playwright.Browser.

A BrowserContext does not share cookies/cache with other BrowserContexts and is somewhat equivalent to an "incognito" browser "window".

Example

# create a new "incognito" browser context.
{:ok, context} = Browser.new_context(browser)

# create a new page in a pristine context.
{:ok, page} = BrowserContext.new_page(context)

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

Returns

  • {:ok, Playwright.BrowserContext.t()}

Arguments

key / nametypedescription
accept_downloadsoptionboolean()Whether to automatically download all the attachments. If false, all the downloads are canceled. (default: false)
...option......

Specs

new_page(t()) :: {:ok, Playwright.Page.t()}

Create a new Playwright.Page for this Browser, within a new "owned" Playwright.BrowserContext.

Closing this page will close the context as well.

This is a convenience API function that should only be used for single-page scenarios and short snippets. Production code and testing frameworks should explicitly create via Playwright.Browser.new_context/2 followed by Playwright.BrowserContext.new_page/2, given the new context, to manage resource lifecycles.