gleewright/browser

Launching browsers and browser contexts.

You usually don’t need this module: the test runner in gleewright launches a browser and gives every test a fresh page in its own context. It is useful for scripting Playwright outside of a test run:

use browser <- step.try(browser.launch(browser.Chromium, headless: True, slow_mo: 0))
use context <- step.try(browser.new_context(
  browser,
  base_url: "",
  viewport_width: 1280,
  viewport_height: 720,
  timeout: 10_000,
))
use page <- step.try(page.new(context))
use _ <- step.try(page.goto(page, "https://example.com"))
use _ <- step.try(page.screenshot(page, "example.png"))
browser.close(browser)

Types

A running browser instance.

pub type Browser

Which browser engine to run tests in.

pub type BrowserType {
  Chromium
  Firefox
  Webkit
}

Constructors

  • Chromium

    Chromium, the open source base of Chrome and Edge.

  • Firefox

    Firefox.

  • Webkit

    WebKit, the engine behind Safari.

An isolated browser session, with its own cookies and storage.

pub type Context

Values

pub fn browser_type_from_string(
  name: String,
) -> Result(BrowserType, Nil)

Parse a browser name. Accepts "chromium", "chrome", "firefox", "webkit" and "safari".

pub fn browser_type_to_string(
  browser_type: BrowserType,
) -> String

The name Playwright uses for a browser type, e.g. "chromium".

pub fn close(browser: Browser) -> step.Step(Nil)

Close a browser and all of its pages.

pub fn close_context(context: Context) -> step.Step(Nil)

Close a context and all of its pages.

pub fn launch(
  browser_type: BrowserType,
  headless headless: Bool,
  slow_mo slow_mo: Int,
) -> step.Step(Browser)

Launch a browser.

pub fn new_context(
  browser: Browser,
  base_url base_url: String,
  viewport_width width: Int,
  viewport_height height: Int,
  timeout timeout: Int,
) -> step.Step(Context)

Create a new isolated context. Relative URLs passed to page.goto are resolved against base_url; pass "" for no base URL. timeout is the default timeout in milliseconds for actions and navigations.

✨ Search Document