GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • playwright

This view

  • Original page
  • New address

GeezerVison is showing playwright.hexdocs.pm — Playwright.Browser — playwright v1.49.1-alpha.2

View Source Playwright.Browser (playwright v1.49.1-alpha.2)

A Playwright.Browser instance is created via:

  • Playwright.BrowserType.launch/0, when using the "driver" transport.
  • Playwright.BrowserType.connect/1, when using the "websocket" transport.

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

alias Playwright.{Browser, Page}

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

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

Properties

  • :name
  • :version

Summary

Types

event()

Supported events

options()

A map/struct providing call options

t()

%Playwright.Browser{}

Functions

close(browser)

Closes the browser.

contexts(browser)

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

init(owner, initializer)

Optional callback implementation for Playwright.SDK.ChannelOwner.init/2.

new_context(browser, options \\ %{})

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

new_page(browser, options \\ %{})

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

version(owner)

Returns the browser version

Types

Link to this type

event()

View Source
@type event() :: :disconnected

Supported events

Link to this type

options()

View Source
@type options() :: map()

A map/struct providing call options

Link to this type

t()

View Source
@type t() :: %Playwright.Browser{
  guid: term(),
  initializer: term(),
  listeners: term(),
  name: term(),
  parent: term(),
  session: term(),
  type: term(),
  version: term()
}

%Playwright.Browser{}

Functions

Link to this function

close(browser)

View Source

Closes the browser.

Given a Playwright.Browser obtained from Playwright.BrowserType.launch/2, closes the Browser and all of its Pages (if any were opened).

Given a Playwright.Browser obtained via Playwright.BrowserType.connect/2, clears all created Contexts belonging to this Browser and disconnects from the browser server.

The Browser object itself is considered to be disposed and cannot be used anymore.

Returns

  • :ok
Link to this function

contexts(browser)

View Source
@spec contexts(t()) :: [Playwright.BrowserContext.t()]

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

Example

contexts = Browser.contexts(browser)
asset Enum.empty?(contexts)

Browser.new_context(browser)

contexts = Browser.contexts(browser)
assert length(contexts) == 1
Link to this function

init(owner, initializer)

View Source
@spec init(
  struct(),
  map()
) :: {atom(), struct()}

Optional callback implementation for Playwright.SDK.ChannelOwner.init/2.

If implemented, the callback will receive:

  1. The newly created "channel owner" struct.
  2. The :initializer received from the Playwright browser server.

The implementation has the option of "patching" the struct as stored in the catalog, and/or binding event handlers.

Example

def init(%{session: session} = owner, _initializer) do
  Channel.bind(session, {:guid, owner.guid}, :close, fn event ->
    Logger.warning("Closing #{inspect(event.target)}")
  end)

  {:ok, %{owner | version: "1.2.3"}}
end

Returns

  • {:ok, struct()}

Arguments

key/nametypedescription
ownerparamstruct()The newly created channel owner (resource).
initializerparamstruct()The initializer received from with the channel owner instance was derived.
Link to this function

new_context(browser, options \\ %{})

View Source
@spec new_context(t(), options()) :: 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.
context = Browser.new_context(browser)

# create a new page in a pristine context.
page = BrowserContext.new_page(context)

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

Returns

  • 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......
Link to this function

new_page(browser, options \\ %{})

View Source
@spec new_page(t(), options()) :: Playwright.Page.t()

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

That is, Playwright.Browser.new_page/2 will also create a new Playwright.BrowserContext. That BrowserContext becomes, both, the parent of the Page, and owned by the Page. When the Page closes, the context goes with it.

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.

Link to this function

version(owner)

View Source
@spec version(t()) :: term()

Returns the browser version

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.