Page interactions via native CDP methods.
All functions return {:ok, result}, :ok, or {:error, exception} where
exception is one of:
%LightCDP.ElementNotFoundError{}— selector matched no element%LightCDP.TimeoutError{}— operation exceeded its deadline%LightCDP.JavaScriptError{}— JS expression threw an exception%LightCDP.CDPError{}— CDP protocol error
Native CDP methods used
| Function | CDP methods |
|---|---|
click/3 | DOM.querySelector -> DOM.getBoxModel -> Input.dispatchMouseEvent |
fill/4 | DOM.resolveNode -> Runtime.callFunctionOn -> Input.insertText |
content/1 | DOM.getDocument -> DOM.getOuterHTML |
navigate/3 | Page.navigate + Page.loadEventFired event |
evaluate/3 | Runtime.evaluate |
url/1 | Runtime.evaluate (no native equivalent) |
submit/4 | Runtime.evaluate (no native equivalent for form submission) |
Timeouts
All functions accept a timeout: option in milliseconds.
| Default | Functions |
|---|---|
| 30,000 ms | navigate, wait_for_navigation, submit |
| 15,000 ms | evaluate, click, fill, wait_for_selector |
Summary
Functions
Clicks an element matching selector.
Returns the full page HTML including doctype.
Evaluates a JavaScript expression and returns the result.
Fills an input element matching selector with value.
Navigates to url and waits for the page to load.
Captures a screenshot of the page as a PNG binary.
Fills form fields, submits the form, and waits for navigation.
Returns the current page URL.
Registers an event waiter, calls fun, then waits for a Page.loadEventFired event.
Polls the DOM until an element matching selector appears.
Functions
Clicks an element matching selector.
Uses native CDP: finds the element via DOM.querySelector, computes its
center point from DOM.getBoxModel, and dispatches mouse events via
Input.dispatchMouseEvent.
Options
:timeout- milliseconds (default:15_000)
Example
:ok = LightCDP.Page.click(page, "#submit-btn")
{:error, %LightCDP.ElementNotFoundError{selector: "#nope"}} = LightCDP.Page.click(page, "#nope")
Returns the full page HTML including doctype.
Uses native DOM.getOuterHTML instead of JavaScript.
Example
{:ok, html} = LightCDP.Page.content(page)
Evaluates a JavaScript expression and returns the result.
Options
:timeout- milliseconds (default:15_000)
Examples
{:ok, "Example Domain"} = LightCDP.Page.evaluate(page, "document.title")
{:ok, 42} = LightCDP.Page.evaluate(page, "21 * 2")
{:error, %LightCDP.JavaScriptError{}} = LightCDP.Page.evaluate(page, "throw new Error('boom')")
Fills an input element matching selector with value.
Uses native CDP: resolves the DOM node, focuses it via
Runtime.callFunctionOn, clears existing content, then types
via Input.insertText.
Options
:timeout- milliseconds (default:15_000)
Example
:ok = LightCDP.Page.fill(page, "#email", "user@example.com")
Captures a screenshot of the page as a PNG binary.
Uses native Page.captureScreenshot.
Options
:timeout- milliseconds (default:15_000)
Example
{:ok, png} = LightCDP.Page.screenshot(page)
File.write!("screenshot.png", png)
Fills form fields, submits the form, and waits for navigation.
fields is a map of %{selector => value} pairs to fill before submitting.
Options
:timeout- milliseconds (default:30_000)
Example
:ok = LightCDP.Page.submit(page, "#login-form", %{
"#email" => "user@example.com",
"#password" => "secret"
})
# Submit with no fields
:ok = LightCDP.Page.submit(page, "form")
Returns the current page URL.
Example
{:ok, "https://example.com/"} = LightCDP.Page.url(page)
Polls the DOM until an element matching selector appears.
Returns :ok when found, {:error, :timeout} if it doesn't appear
within the timeout.
Options
:timeout- milliseconds (default:15_000):interval- polling interval in milliseconds (default:100)
Example
:ok = LightCDP.Page.wait_for_selector(page, ".search-results", timeout: 5_000)