ChromeDPClient

class ChromeDPClient(remoteDebugUrl: String = "http://localhost:9222", overrideHostHeader: Boolean = false, httpClient: HttpClient = ChromeDP.defaultHttpClient) : ChromeDPHttpApi(source)

Deprecated

The entrypoint API has be reworked to favor the web socket connection approach. Use ChromeDP.connect() instead to connect to the debugger. Please check the docs and the KDoc of ChromeDP for more info. Moreover, the ChromeDPClient concrete type shouldn't be referenced as-is anymore, and will be hidden or removed in a future version. If you still need to access similar HTTP API methods, please use the ChromeDPHttpApi interface instead.

Replace with

import org.hildan.chrome.devtools.protocol.ChromeDPHttpApi
ChromeDPHttpApi

A client using the Chrome Devtools Protocol to communicate with a running Chrome browser via the debugger API.

It provides access to the HTTP endpoints exposed by the Chrome browser, as well as web socket connections to the browser and its targets to make use of the full Chrome Devtools Protocol API.

Note: if you already know the browser target's web socket URL, you don't need to create a ChromeDPClient. Instead, you can directly use HttpClient.chromeWebSocket.

Host override

Chrome doesn't accept a Host header that is not an IP nor localhost, but in some environments the URL has to have a named host (e.g. docker services in a docker swarm, communicating using service names).

Enabling overrideHostHeader works around this problem by setting the Host header to "localhost" in the HTTP requests to the Chrome debugger. It also restores the original host in URLs that are returned by Chrome (Chrome uses the Host header to build the URLs that it returns, so they would contain localhost otherwise).

Constructors

Link copied to clipboard
constructor(remoteDebugUrl: String = "http://localhost:9222", overrideHostHeader: Boolean = false, httpClient: HttpClient = ChromeDP.defaultHttpClient)

Functions

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

Brings the page identified by the given targetId into the foreground (activates a tab).

Link copied to clipboard
open suspend fun closeAllTargets()

Closes all targets.

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

Closes the page identified by targetId.

Link copied to clipboard
open suspend override fun newTab(url: String): ChromeDPTarget

Opens a new tab, and returns the websocket target data for the new tab.

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

Fetches the current Chrome DevTools Protocol definition, as a JSON string.

Link copied to clipboard
open suspend override fun targets(): List<ChromeDPTarget>

Fetches the list of all available web socket targets (e.g. browser tabs).

Link copied to clipboard
open suspend override fun version(): ChromeVersion

Fetches the browser version metadata via the debugger's HTTP API.

Link copied to clipboard
open suspend override fun webSocket(): BrowserSession

Opens a web socket connection to interact with the browser.