Skip to content

Page API

The Page object combines native CDP transport methods with high-level Lua helpers.

async

Raw page-level CDP command.

async

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.

async

Wait for a page-level CDP notification. Accepts variadic args: timeout (number), predicate (function), or a table with timeout_ms/timeout and predicate.

sync

Closes the specific tab.


page:open(url, [wait_until], [timeout_ms])

Section titled “page:open(url, [wait_until], [timeout_ms])”
async

Returns true or nil, error.

local ok, err = page:open("https://example.com")
if not ok then
log("Navigation failed: " .. tostring(err))
end
async

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()
end

page:wait_for_idle([timeout_ms], [quiet_ms])

Section titled “page:wait_for_idle([timeout_ms], [quiet_ms])”
async

Wait for network idle.

async

Polls location.href until it matches the string pattern. Returns the URL or nil, error.


async

Returns the result of the JavaScript expression.

local title = page:evaluate("document.title")
local count = page:evaluate("document.querySelectorAll('.item').length")
async

Returns the full rendered HTML.

local html = page:content()
async

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 })

async

Click an element. opts.real = true uses hardware mouse events.

page:click("button.submit")
page:click("button.submit", { real = true })
async

Type text into an element. opts.real = true uses hardware keyboard events.

page:type("input.search", "hello world")
async

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" })
async

Sets extra HTTP headers via Network.setExtraHTTPHeaders.

async

Overrides the User-Agent. opts can include accept_language and platform.


async

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])”
async

Waits for Network.responseReceived. Optional predicate function receives params, returns true when match found.

async

Returns all cookies, or filtered by URL if urls is provided.

async

Sets cookies via Network.setCookies.