PlaywrightEx.BrowserContext (PlaywrightEx v0.2.0)

View Source

Interact with a Playwright BrowserContext.

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

References:

Summary

Functions

Adds cookies into this browser context.

Removes cookies from this browser context.

Closes the browser context.

Creates a new page in the browser context.

Registers a custom selector engine.

Types

add_cookies_opt()

@type add_cookies_opt() :: {:timeout, timeout()} | {:cookies, [term()]}

clear_cookies_opt()

@type clear_cookies_opt() ::
  {:timeout, timeout()} | {:domain, term()} | {:name, term()} | {:path, term()}

close_opt()

@type close_opt() :: {:timeout, timeout()} | {:reason, binary()}

new_page_opt()

@type new_page_opt() :: {:timeout, timeout()}

register_selector_engine_opt()

@type register_selector_engine_opt() ::
  {:timeout, timeout()} | {:selector_engine, keyword()}

Functions

add_cookies(context_id, opts \\ [])

@spec add_cookies(PlaywrightEx.guid(), [
  add_cookies_opt() | PlaywrightEx.unknown_opt()
]) ::
  {:ok, any()} | {:error, any()}

Adds cookies into this browser context.

Reference: https://playwright.dev/docs/api/class-browsercontext#browser-context-add-cookies

Options

  • :timeout (timeout/0) - Required. Maximum time for the operation (milliseconds).

  • :cookies (list of term/0) - Required. Adds cookies into this browser context. All pages within this context will have these cookies installed.

clear_cookies(context_id, opts \\ [])

@spec clear_cookies(PlaywrightEx.guid(), [
  clear_cookies_opt() | PlaywrightEx.unknown_opt()
]) ::
  {:ok, any()} | {:error, any()}

Removes cookies from this browser context.

Reference: https://playwright.dev/docs/api/class-browsercontext#browser-context-clear-cookies

Options

  • :timeout (timeout/0) - Required. Maximum time for the operation (milliseconds).

  • :domain (term/0) - Only removes cookies with the given domain.

  • :name (term/0) - Only removes cookies with the given name.

  • :path (term/0) - Only removes cookies with the given path.

close(browser_id, opts \\ [])

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

Closes the browser context.

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

Options

  • :timeout (timeout/0) - Required. Maximum time for the operation (milliseconds).

  • :reason (String.t/0) - The reason to be reported to the operations interrupted by the context closure.

new_page(context_id, opts \\ [])

@spec new_page(PlaywrightEx.guid(), [new_page_opt() | PlaywrightEx.unknown_opt()]) ::
  {:ok, %{guid: PlaywrightEx.guid(), main_frame: %{guid: PlaywrightEx.guid()}}}
  | {:error, any()}

Creates a new page in the browser context.

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

Options

  • :timeout (timeout/0) - Required. Maximum time for the operation (milliseconds).

register_selector_engine(context_id, opts \\ [])

@spec register_selector_engine(PlaywrightEx.guid(), [
  register_selector_engine_opt() | PlaywrightEx.unknown_opt()
]) :: :ok | {:error, any()}

Registers a custom selector engine.

Reference: https://playwright.dev/docs/api/class-selectors#selectors-register

Options

  • :timeout (timeout/0) - Required. Maximum time for the operation (milliseconds).

  • :selector_engine (non-empty keyword/0) - Required.

    • :name (String.t/0) - Required. Name that is used in selectors as a prefix.

    • :source (String.t/0) - Required. Script that evaluates to a selector engine instance.