Behaviour defining the transport interface for Playwright communication.
Transports abstract how Playwriter communicates with Playwright:
Playwriter.Transport.Local- Uses playwright_ex with Erlang PortsPlaywriter.Transport.Remote- Uses WebSocket to remote Playwright server
Summary
Callbacks
Add cookies to a context. Each cookie is a map using Playwright's field names
(name, value, and either url or domain+path; optionally expires,
httpOnly, secure, sameSite). Used to seed a signed session cookie so
tests can start past an auth gate without driving the login UI.
Add an init script to a context, evaluated before any page scripts on every page/navigation in that context. Targets a context guid, so it must be installed before the page is created.
Send a CDP command over a session opened with new_cdp_session/2
(e.g. Network.emulateNetworkConditions). Windows transport only.
Click an element
Close a browser
Close a context
Close a page
Get page content
Evaluate a JavaScript expression in a frame and return the result.
Expose an Elixir callback to the page as a binding: the page can call
window.<name>(...args) and the transport invokes the callback with the
argument list, returning its result to the page.
Fill an input
Navigate to a URL
Check if transport is healthy
Launch a browser instance
Open a Chrome DevTools Protocol session for a page. Returns an opaque CDP
session id to be used with cdp_send/4.
Create a new browser context
Create a new page in a context
Take a screenshot
Send a message to Playwright and wait for response
Start the transport connection
Stop the transport
Return the context's storage state (cookies + localStorage snapshot), e.g. to
capture it after a UI login and re-seed it (via add_cookies/3) in later runs.
Wait until a JavaScript predicate becomes truthy in a frame.
Types
Callbacks
Add cookies to a context. Each cookie is a map using Playwright's field names
(name, value, and either url or domain+path; optionally expires,
httpOnly, secure, sameSite). Used to seed a signed session cookie so
tests can start past an auth gate without driving the login UI.
Add an init script to a context, evaluated before any page scripts on every page/navigation in that context. Targets a context guid, so it must be installed before the page is created.
Send a CDP command over a session opened with new_cdp_session/2
(e.g. Network.emulateNetworkConditions). Windows transport only.
Click an element
Close a browser
Close a context
Close a page
Get page content
Evaluate a JavaScript expression in a frame and return the result.
opts may include :is_function (treat the expression as a function body),
:arg (an argument passed to the function), and :timeout.
@callback expose_binding(transport(), guid(), String.t(), (list() -> term())) :: :ok | {:error, term()}
Expose an Elixir callback to the page as a binding: the page can call
window.<name>(...args) and the transport invokes the callback with the
argument list, returning its result to the page.
Experimental and :windows-only - it is the one verb that needs the
bidirectional event channel. :local/:remote return
{:error, :not_supported}. Most harness needs are met by polling with
evaluate/4 + wait_for_function/4; prefer those.
Fill an input
Navigate to a URL
Check if transport is healthy
@callback launch_browser(transport(), browser_type(), keyword()) :: {:ok, guid()} | {:error, term()}
Launch a browser instance
Open a Chrome DevTools Protocol session for a page. Returns an opaque CDP
session id to be used with cdp_send/4.
Only the :windows transport supports CDP; :local returns
{:error, :not_supported} (playwright_ex exposes no CDP surface).
Create a new browser context
Create a new page in a context
Take a screenshot
Send a message to Playwright and wait for response
Start the transport connection
@callback stop(transport()) :: :ok
Stop the transport
Return the context's storage state (cookies + localStorage snapshot), e.g. to
capture it after a UI login and re-seed it (via add_cookies/3) in later runs.
@callback wait_for_function(transport(), guid(), String.t(), keyword()) :: {:ok, term()} | {:error, term()}
Wait until a JavaScript predicate becomes truthy in a frame.
opts may include :is_function, :arg, :polling (a number of ms or
"raf"), and :timeout.