Page

interface Page

One page, driven programmatically.

Every call suspends, takes a timeout, and cancels cleanly: cancelling the calling coroutine destroys the session on every path, including mid-navigation. Once close has run, every call raises ErrorCode.DETACHED.

A timeout defaulting to zero means "use the value from BrowserConfig.timeouts".

The shape is Playwright's on purpose. Anyone who knows that API knows this one.

Inheritors

Functions

Link copied to clipboard
abstract suspend fun addInitScript(script: String, allowedOrigins: Set<String>)

Installs a script that runs before any page script, on this and every subsequent document.

Link copied to clipboard
abstract suspend fun blockResourceTypes(vararg types: ResourceType)

Blocks loading of specific resource categories (e.g. ResourceType.Images, ResourceType.Fonts).

Link copied to clipboard
abstract suspend fun capabilities(): Capabilities

What this session can do. Branch on it instead of discovering a gap through a failure.

Link copied to clipboard
abstract suspend fun clearCookies(domain: String? = null)

Clears cookies for a domain, or all of them when domain is null.

Link copied to clipboard
abstract suspend fun clearStorage()

Clears local storage, session storage and IndexedDB.

Link copied to clipboard
abstract suspend fun click(selector: String, timeoutMillis: Long = 0)

Waits for the element, scrolls it into view, then clicks it.

Link copied to clipboard
abstract suspend fun close()

Destroys the session. Every path ends here, including cancellation and exceptions. Safe to call twice.

Link copied to clipboard
abstract suspend fun content(): String

The document's serialised HTML. Subject to the same cap as text.

Link copied to clipboard
abstract suspend fun cookies(url: String): List<Cookie>

Cookie storage is process-global: these are not scoped to this session.

Link copied to clipboard
abstract suspend fun evaluate(expression: String, timeoutMillis: Long = 0): String?

Evaluates an expression in page context and returns its value.

Link copied to clipboard
abstract suspend fun exposeFunction(name: String, allowedOrigins: Set<String>, handler: suspend (String) -> String?)

Exposes a native function to page context, over an origin-scoped channel.

Link copied to clipboard
abstract suspend fun fillTime(selector: String, time: String, timeoutMillis: Long = 0)

Sets the value of a time-typed input, for example "14:30".

Link copied to clipboard
abstract suspend fun frames(): List<Frame>

Every frame currently attached to the page, including the main frame.

Link copied to clipboard
abstract suspend fun goto(url: String, waitUntil: WaitUntil = WaitUntil.Load, timeoutMillis: Long = 0): NavigationResult

Navigates and waits for waitUntil.

Link copied to clipboard
abstract suspend fun hover(selector: String, timeoutMillis: Long = 0)

Waits for the element, then moves the pointer over it without clicking.

Link copied to clipboard
abstract fun onConsole(listener: (ConsoleMessage) -> Unit)

Registers a callback fired for every console message logged by the page.

Link copied to clipboard
abstract fun onDialog(listener: suspend (Dialog) -> Unit)

Dialogs block the page until answered. Without a listener they are dismissed.

Link copied to clipboard
abstract fun onRequest(listener: (Request) -> Unit)

Registers a callback fired for every outgoing request.

Link copied to clipboard
abstract fun onResponse(listener: (Response) -> Unit)

Registers a callback fired for every received response.

Link copied to clipboard
abstract suspend fun press(key: String, timeoutMillis: Long = 0)

Presses a key against the focused element, for example Enter.

Link copied to clipboard
abstract suspend fun querySelector(selector: String): Element
Link copied to clipboard
abstract suspend fun querySelectorAll(selector: String): List<Element>

Empty when nothing matches. Unlike querySelector, this is not an error.

Link copied to clipboard
abstract suspend fun route(pattern: String, handler: suspend (Route) -> Unit)

Routes requests matching a glob pattern, such as one selecting every png, jpg and woff2 under any path.

Link copied to clipboard
abstract suspend fun screenshot(format: ImageFormat = ImageFormat.Png, quality: Int = 90): ByteArray

Captures the viewport by drawing the view.

Link copied to clipboard
abstract suspend fun scrollIntoView(selector: String, timeoutMillis: Long = 0)

Waits for the element, then scrolls the viewport so it is visible.

Link copied to clipboard
abstract suspend fun selectOption(selector: String, value: String, timeoutMillis: Long = 0)

Waits for the element, then selects an option on a <select> by its value.

Link copied to clipboard
abstract suspend fun setCookie(cookie: Cookie)

Writes a cookie into the process-global jar.

Link copied to clipboard
abstract suspend fun setExtraHeaders(headers: Map<String, String>)

Merges headers into every subsequent outgoing request.

Link copied to clipboard
abstract suspend fun setUserAgent(userAgent: String)

Overrides the User-Agent header sent with every subsequent request.

Link copied to clipboard
abstract suspend fun text(): String

The rendered text of the document. Capped; oversized output is truncated and reported.

Link copied to clipboard
abstract suspend fun title(): String

The document's <title> text.

Link copied to clipboard
abstract suspend fun type(selector: String, text: String, timeoutMillis: Long = 0)

Types into the element, firing the input and change events a framework needs.

Link copied to clipboard
abstract suspend fun url(): String

The document actually loaded, which after a redirect is not the requested URL.

Link copied to clipboard
abstract suspend fun waitForFunction(expression: String, timeoutMillis: Long = 0)

Waits until a JavaScript expression is truthy.

Link copied to clipboard
abstract suspend fun waitForSelector(selector: String, timeoutMillis: Long = 0): Element

Waits for an element to exist. Returns as soon as it appears, not on a poll tick.