Page API
The Page object combines native CDP transport methods with high-level Lua helpers.
Native Methods
Section titled “Native Methods”page:call(method, params)
Section titled “page:call(method, params)”Raw page-level CDP command.
page:call_save(method, params, path)
Section titled “page:call_save(method, params, path)”Optimized binary call. Saves the data field of the response to path and returns the JSON without the massive data string. Supports .png, .jpg, .pdf, .zip, etc.
page:wait_event(event, ...)
Section titled “page:wait_event(event, ...)”Wait for a page-level CDP notification. Accepts variadic args: timeout (number), predicate (function), or a table with timeout_ms/timeout and predicate.
page:close()
Section titled “page:close()”Closes the specific tab.
Navigation
Section titled “Navigation”page:open(url, [wait_until], [timeout_ms])
Section titled “page:open(url, [wait_until], [timeout_ms])”Returns true or nil, error.
local ok, err = page:open("https://example.com")if not ok then log("Navigation failed: " .. tostring(err))endpage:wait_for_selector(selector, [opts])
Section titled “page:wait_for_selector(selector, [opts])”Returns true, element_info or nil, error. opts can be timeout (number) or {timeout, poll_ms, visible, scroll}.
local found = page:wait_for_selector(".content", 10000)if found then local html = page:content()endpage:wait_for_idle([timeout_ms], [quiet_ms])
Section titled “page:wait_for_idle([timeout_ms], [quiet_ms])”Wait for network idle.
page:wait_for_url(pattern, timeout_ms)
Section titled “page:wait_for_url(pattern, timeout_ms)”Polls location.href until it matches the string pattern. Returns the URL or nil, error.
Evaluation
Section titled “Evaluation”page:evaluate(js)
Section titled “page:evaluate(js)”Returns the result of the JavaScript expression.
local title = page:evaluate("document.title")local count = page:evaluate("document.querySelectorAll('.item').length")page:content()
Section titled “page:content()”Returns the full rendered HTML.
local html = page:content()page:screenshot(path, [opts])
Section titled “page:screenshot(path, [opts])”Saves a screenshot. Subject to 10MB response limit.
| Option | Type | Default | Description |
|---|---|---|---|
format |
string | "png" |
"png" or "jpeg" |
quality |
number | - | 1-100 (jpeg only) |
full_page |
boolean | false |
Capture full page |
fromSurface |
boolean | - | Capture from surface |
page:screenshot("page.png")page:screenshot("page.jpg", { format = "jpeg", quality = 80, full_page = true })Interaction
Section titled “Interaction”page:click(selector, [opts])
Section titled “page:click(selector, [opts])”Click an element. opts.real = true uses hardware mouse events.
page:click("button.submit")page:click("button.submit", { real = true })page:type(selector, text, [opts])
Section titled “page:type(selector, text, [opts])”Type text into an element. opts.real = true uses hardware keyboard events.
page:type("input.search", "hello world")page:scroll([opts])
Section titled “page:scroll([opts])”Scrolls the page.
| Option | Type | Default | Description |
|---|---|---|---|
max_scrolls |
number | 20 | Maximum scroll attempts |
step |
number | - | Pixels to scroll per step |
delay_ms |
number | 250 | Delay between scrolls |
until_selector |
string | - | Scroll until selector appears |
until_bottom |
boolean | true |
Scroll until page bottom |
page:scroll({ until_selector = ".footer" })page:set_extra_headers(headers)
Section titled “page:set_extra_headers(headers)”Sets extra HTTP headers via Network.setExtraHTTPHeaders.
page:set_user_agent(user_agent, [opts])
Section titled “page:set_user_agent(user_agent, [opts])”Overrides the User-Agent. opts can include accept_language and platform.
Network
Section titled “Network”page:block_resources(types)
Section titled “page:block_resources(types)”Block resource types.
page:block_resources({"image", "font", "media"})page:wait_for_response([predicate], [timeout_ms])
Section titled “page:wait_for_response([predicate], [timeout_ms])”Waits for Network.responseReceived. Optional predicate function receives params, returns true when match found.
page:cookies([urls])
Section titled “page:cookies([urls])”Returns all cookies, or filtered by URL if urls is provided.
page:set_cookies(cookies)
Section titled “page:set_cookies(cookies)”Sets cookies via Network.setCookies.