PlaywrightEx.Browser (PlaywrightEx v0.2.0)

View Source

Interact with a Playwright Browser.

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

References:

Summary

Functions

Closes the browser and all of its contexts.

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

Types

close_opt()

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

new_context_opt()

@type new_context_opt() ::
  {: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()}

Functions

close(browser_id, opts \\ [])

@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

  • :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 browser closure.

new_context(browser_id, opts \\ [])

@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

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

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

  • :base_url (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 (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 (float/0) - Specify device scale factor (can be thought of as dpr). Defaults to 1.

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

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

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

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

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

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

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

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