DefaultTab

open class DefaultTab(websocketUrl: String, messageListeningScope: CoroutineScope, var targetInfo: <Error class: unknown class>, var owner: Browser? = null) : DefaultConnection, Tab

Represents a browser tab, which is a connection to a specific target in the browser.

This class provides methods to interact with the tab, such as navigating to URLs, managing history, evaluating JavaScript expressions, and manipulating the DOM.

Constructors

Link copied to clipboard
constructor(websocketUrl: String, messageListeningScope: CoroutineScope, targetInfo: <Error class: unknown class>, owner: Browser? = null)

Properties

Link copied to clipboard
open val attached: Boolean?
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open val events: Flow<<Error class: unknown class>>
Link copied to clipboard
open val generatedDomains: MutableMap<KClass<out <Error class: unknown class>>, <Error class: unknown class>>
Link copied to clipboard
open override var lastMouseX: Double?

Last mouse X position for this tab (for natural trajectories in anti-detection). Each tab maintains its own mouse position to prevent concurrent operations from interfering.

Link copied to clipboard
open override var lastMouseY: Double?

Last mouse Y position for this tab (for natural trajectories in anti-detection). Each tab maintains its own mouse position to prevent concurrent operations from interfering.

Link copied to clipboard
Link copied to clipboard
open val openerId: String?
Link copied to clipboard
open override var owner: Browser?
Link copied to clipboard
open val responses: Flow<<Error class: unknown class>>
Link copied to clipboard
open val subtype: String?
Link copied to clipboard
open val targetId: String?
Link copied to clipboard
open override var targetInfo: <Error class: unknown class>?
Link copied to clipboard
open val title: String?
Link copied to clipboard
open val type: String?
Link copied to clipboard
open val url: String?

Functions

Link copied to clipboard
open suspend override fun activate()

Activates the tab, bringing it to the foreground.

Link copied to clipboard
inline fun <T> Connection.addHandler(coroutineScope: CoroutineScope, crossinline event: <Error class: unknown class>.() -> Flow<T>, crossinline handler: suspend (T) -> Unit): Job

Adds a handler for a specific CDP event.

Link copied to clipboard
open suspend override fun back()

Navigate back in the tab's history.

Link copied to clipboard
open suspend override fun bringToFront()

Brings the tab to the front, activating it.

Link copied to clipboard
open suspend override fun callCommand(method: String, parameter: JsonElement?, mode: <Error class: unknown class>): JsonElement?

Internal method to call a CDP command.

Link copied to clipboard
open suspend override fun close()

Closes the websocket connection. Should not be called manually by users.

Link copied to clipboard
open suspend override fun disableDomAgent()

Disables the DOM agent to stop receiving DOM-related events.

Link copied to clipboard
inline suspend fun <T> Tab.evaluate(expression: String, awaitPromise: Boolean = false): T?

Evaluates a JavaScript expression in the context of the tab.

Link copied to clipboard
open suspend override fun <T> expect(urlPattern: <Error class: unknown class>, block: suspend RequestExpectation.() -> T): T

Expects a request to match the given urlPattern.

Link copied to clipboard
open suspend override fun <T> expectBatch(urlPatterns: List<<Error class: unknown class>>, block: suspend BatchRequestExpectation.() -> T): T

Expects multiple requests matching the given list of urlPatterns. All expectations are active concurrently during block.

Link copied to clipboard
open suspend override fun find(text: String, bestMatch: Boolean, returnEnclosingElement: Boolean, timeout: Long): Element

Finds a single element by its text content, optionally waiting for it to appear.

Link copied to clipboard
open suspend override fun findAll(text: String, timeout: Long): List<Element>

Finds multiple elements by their text content, optionally waiting for them to appear.

Link copied to clipboard
open suspend override fun findElementByText(text: String, bestMatch: Boolean, returnEnclosingElement: Boolean): Element?

Finds and returns the first element containing the specified text, or the best match if bestMatch is true.

Link copied to clipboard
open suspend override fun findElementsByText(text: String, tagHint: String?): List<Element>

Returns elements which match the given text. Please note: this may (or will) also return any other element (like inline scripts), which happen to contain that text.

Link copied to clipboard
open suspend override fun forward()

Navigate forward in the tab's history.

Link copied to clipboard
open suspend override fun fullscreen()

Sets the tab's window to fullscreen mode.

Link copied to clipboard
open suspend override fun get(url: String, newTab: Boolean, newWindow: Boolean): Tab

Navigate to a specified URL in the tab.

Link copied to clipboard
open suspend override fun getAllLinkedSources(): List<Element>

Gets all elements of tag: link, a, img, script, meta.

Link copied to clipboard
open suspend override fun getAllUrls(absolute: Boolean): List<String>

Convenience function, which returns all links (a, link, img, script, meta).

Link copied to clipboard
open suspend override fun getContent(): String

Gets the content of the tab as a string.

Link copied to clipboard
open suspend override fun getWindow(): <Error class: unknown class>

Gets the current window information for the tab.

Link copied to clipboard
open suspend override fun <T> intercept(urlPattern: String, requestStage: <Error class: unknown class>, resourceType: <Error class: unknown class>, block: suspend FetchInterception.() -> T): T

Intercepts network requests matching the given urlPattern and requestStage. This allows you to modify requests, responses, or block them entirely.

Link copied to clipboard
open suspend override fun maximize()

Maximizes the tab's window.

Link copied to clipboard
open suspend override fun medimize()

Restores the tab's window to its normal state.

Link copied to clipboard
open suspend override fun minimize()

Minimizes the tab's window.

Link copied to clipboard
open suspend override fun mouseClick(x: Double, y: Double, button: <Error class: unknown class>, buttons: Int, modifiers: Int)

Performs a native mouse click at the specified \[x, y\] coordinates.

Link copied to clipboard
open suspend override fun mouseMove(x: Double, y: Double, steps: Int, flash: Boolean)

Moves the mouse cursor to the specified \[x, y\] coordinates, optionally in multiple steps and with a flash effect.

Link copied to clipboard
open suspend override fun querySelector(selector: String, node: NodeOrElement?): Element?

Finds a single element based on a CSS selector string.

Link copied to clipboard
open suspend override fun querySelectorAll(selector: String, node: NodeOrElement?): List<Element>

Equivalent of JavaScript's document.querySelectorAll. This is considered one of the main methods to use in this package.

Link copied to clipboard
open suspend override fun rawEvaluate(expression: String, awaitPromise: Boolean): JsonElement?

Evaluates a JavaScript expression in the context of the tab.

Link copied to clipboard
open suspend override fun reload(ignoreCache: Boolean, scriptToEvaluateOnLoad: String?)

Reload the current page in the tab.

Link copied to clipboard
open suspend override fun saveScreenshot(filename: Path?, format: ScreenshotFormat, fullPage: Boolean): String

Saves a screenshot of the page. This is not the same as Element.saveScreenshot, which saves a screenshot of a single element only.

Link copied to clipboard
open suspend override fun screenshotB64(format: ScreenshotFormat, fullPage: Boolean): String

Takes a screenshot of the page and returns the result as a base64 encoded string. This is not the same as Element.screenshotB64, which takes a screenshot of a single element only.

Link copied to clipboard
open suspend override fun scrollDown(amount: Int, speed: Int)

Scrolls the tab down by a specified amount.

Link copied to clipboard
open suspend override fun scrollTo(scrollX: Double, scrollY: Double, speed: Int?)

Scrolls the page naturally using CDP's synthesizeScrollGesture (P3 - Anti-detection). This creates smooth, human-like scrolling instead of instant jumps.

Link copied to clipboard
open suspend override fun scrollUp(amount: Int, speed: Int)

Scrolls the tab up by a specified amount.

Link copied to clipboard
open suspend override fun select(selector: String, timeout: Long): Element

Selects an element in the DOM using a CSS selector.

Link copied to clipboard
open suspend override fun selectAll(selector: String, timeout: Long, includeFrames: Boolean): List<Element>

Finds multiple elements by CSS selector, optionally waiting for them to appear.

Link copied to clipboard
inline fun <T> Connection.send(command: <Error class: unknown class>.() -> T): T

Sends a CDP command and waits for the response.

Link copied to clipboard
open suspend override fun setUserAgent(userAgent: String?, acceptLanguage: String?, platform: String?)

Sets the user agent for the tab.

Link copied to clipboard
open suspend override fun setWindowState(left: Int, top: Int, width: Int, height: Int, state: String)

Sets the tab's window state, including position and size.

Link copied to clipboard
open suspend override fun sleep(t: Long)

Suspends the coroutine for a specified time in milliseconds.

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
open suspend override fun updateTarget()

Updates the target information by fetching it from the CDP.

Link copied to clipboard
open suspend override fun wait(t: Long?)

Waits until the event listener reports idle (no new events received in a certain timespan). When \`t\` is provided, ensures waiting for \`t\` milliseconds, no matter what.

Link copied to clipboard
open suspend override fun waitForReadyState(until: ReadyState, timeout: Long): Boolean

Waits for the document's ready state to reach a specified state.

Link copied to clipboard
open suspend override fun xpath(xpath: String, timeout: Long): List<Element>

Finds elements by XPath string.