Browser-only helpers for the active Playwright page.
These functions intentionally live under Fluffy.Playwright because they
depend on a real browser. Use them when behavior requires one; they are not
implemented by the Static or LiveView drivers.
Summary
Functions
Adds cookie maps to the browser context and returns the session.
Clears cookies and returns the session. Filters :name, :domain, and :path accept strings or regexes. Accepts :timeout.
Returns browser cookies, optionally filtered by a list of :urls. Accepts :timeout.
Evaluates JavaScript in the active Playwright page and returns the value.
Saves a PNG screenshot of the active page and returns the session.
Returns storage state for reuse as browser_context: [storage_state: state]. Accepts :indexed_db, :timeout, and optional JSON output :path.
Starts a Playwright trace for this session's BrowserContext.
Actions
Blurs the target in the active browser page.
Drags the source locator onto the target locator in the same frame. Requires Playwright.
Focuses the target in the active browser page.
Hovers over a locator. Requires Playwright.
Types text character by character, emitting keyboard events. Accepts :delay in milliseconds. Requires Playwright.
Types
@type evaluate_option() :: {:arg, term()} | {:is_function, boolean()} | {:timeout, nil | non_neg_integer()}
@type screenshot_option() :: {:full_page, boolean()} | {:omit_background, boolean()} | {:timeout, pos_integer()}
Functions
Adds cookie maps to the browser context and returns the session.
Clears cookies and returns the session. Filters :name, :domain, and :path accept strings or regexes. Accepts :timeout.
Returns browser cookies, optionally filtered by a list of :urls. Accepts :timeout.
@spec evaluate(Fluffy.Session.t(), String.t(), [evaluate_option()]) :: term()
Evaluates JavaScript in the active Playwright page and returns the value.
This mirrors Playwright's page/frame evaluation semantics: promises are awaited by Playwright, serializable JavaScript values are returned to Elixir, and JavaScript or protocol failures raise.
evaluate/3 is a browser-only value query, so it returns the evaluated value
rather than the Fluffy session. Use Elixir's then/2 when a pipeline needs
the value and then should continue with the session:
import Fluffy
import Fluffy.Playwright
import Fluffy.Locator
alias Fluffy.Playwright
session
|> then(fn session ->
title = Playwright.evaluate(session, "document.title")
assert title == "Potions classroom"
session
end)
|> click(by_role(:button, name: "Continue"))For function-style expressions, pass is_function: true and arg::
Playwright.evaluate(session, "selector => document.querySelector(selector).textContent",
is_function: true,
arg: "#status"
)Do not use this for JavaScript that owns a navigation, opens a page, starts a
download, or installs a durable listener. Use the corresponding
listener-before-action Fluffy.wait_for/3 event API so lifecycle and
cleanup remain owned by Fluffy. Reserve Fluffy.unwrap/2 for uncommon
page-local operations that have no first-class API.
Options
:arg(term/0) - Serializable argument passed to a function-style expression. The default value isnil.:is_function(boolean/0) - Treat the expression as a JavaScript function. The default value isfalse.:timeout(non_neg_integer/0ornil) - Maximum evaluation time in milliseconds; defaults to the session timeout. The default value isnil.
@spec screenshot(Fluffy.Session.t(), Path.t(), [screenshot_option()]) :: Fluffy.Session.t()
Saves a PNG screenshot of the active page and returns the session.
Options
:full_page(boolean/0) - Capture the full scrollable page instead of only the viewport. The default value isfalse.:omit_background(boolean/0) - Hide the default white background to allow transparency. The default value isfalse.:timeout(pos_integer/0) - Maximum screenshot time in milliseconds.
Returns storage state for reuse as browser_context: [storage_state: state]. Accepts :indexed_db, :timeout, and optional JSON output :path.
@spec trace(Fluffy.Session.t(), [trace_option()]) :: Fluffy.Session.t()
Starts a Playwright trace for this session's BrowserContext.
The trace includes every page in the session and is saved when the test's
lifecycle scope shuts down. Because an explicit trace is primarily a local
debugging request, its viewer opens by default; pass open: false in CI. A
session may start one trace.
Options
:directory(String.t/0) - Directory in which to save the trace archive.:name(String.t/0) - Human-readable trace name and artifact filename prefix.:open(boolean/0) - Open Playwright Trace Viewer after saving the trace. The default value istrue.:screenshots(boolean/0) - Capture screenshots during tracing. The default value istrue.:snapshots(boolean/0) - Capture DOM snapshots and network activity. The default value istrue.:sources(boolean/0) - Include source files in the trace. The default value istrue.
Actions
@spec blur(Fluffy.Session.t(), Fluffy.Locator.t(), [Fluffy.action_option()]) :: Fluffy.Session.t()
Blurs the target in the active browser page.
Drags the source locator onto the target locator in the same frame. Requires Playwright.
@spec focus(Fluffy.Session.t(), Fluffy.Locator.t(), [Fluffy.action_option()]) :: Fluffy.Session.t()
Focuses the target in the active browser page.
Hovers over a locator. Requires Playwright.
Types text character by character, emitting keyboard events. Accepts :delay in milliseconds. Requires Playwright.