chromeWebSocket

suspend fun HttpClient.chromeWebSocket(webSocketDebuggerUrl: String): BrowserSession(source)

Deprecated

The entrypoint API has been reworked to simplify the direct 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. This extension will be removed in a future version of chrome-devtools-kotlin. If you need a custom HttpClient, use HttpClient.connectChromeDebugger(url) instead.

Replace with

import org.hildan.chrome.devtools.connectChromeDebugger
this.connectChromeDebugger(webSocketDebuggerUrl)

Connects to the Chrome debugger at the given webSocketDebuggerUrl.

Note that this HttpClient must have the WebSockets plugin installed.

This function expects a web socket URL (not HTTP). It should be something like:

ws://localhost:9222/devtools/browser/b0b8a4fb-bb17-4359-9533-a8d9f3908bd8

If you're using services like Browserless's Docker image, you might have a simpler URL like ws://localhost:3000 or ws://localhost:3000?token=6R0W53R135510.

If you only have the debugger's HTTP URL at hand (e.g. http://localhost:9222), create a ChromeDPHttpApi instead, and then connect to the web socket using ChromeDPClient.webSocket.

The returned BrowserSession only provides a limited subset of the possible operations, because it is attached to the default browser target, not a page target. To create a new page (tab), use newPage and then interact with it through the returned PageSession. Refer to the documentation of BrowserSession for more info.

The caller of this method is responsible for closing the web socket after use by calling BrowserSession.close, or using the auto-close capabilities via use. Because all child sessions of the returned BrowserSession use the same underlying web socket connection, calling ChildSession.close or use on a derived session doesn't close the connection (to avoid undesirable interactions between child sessions).

See also