-
- All Implemented Interfaces:
public final class ChromeDPClientA Chrome Devtools Protocol client.
It provides access to the basic 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.Chrome doesn't accept a
Hostheader that is not an IP norlocalhost, but in some environments it might be hard to provide this (e.g. docker services in a docker swarm, communicating using service names).To work around this problem, simply set overrideHostHeader to true. This overrides the
Hostheader to "localhost" in the HTTP requests to the Chrome debugger to make it happy, and also replaces the host in subsequent web socket URLs (returned by Chrome) by the initial host provided in remoteDebugUrl. This is necessary because Chrome uses theHostheader to build these URLs, and it would be incorrect to keep this.
-
-
Constructor Summary
Constructors Constructor Description ChromeDPClient(String remoteDebugUrl, Boolean overrideHostHeader, HttpClient httpClient)
-
Method Summary
Modifier and Type Method Description final ChromeVersionversion()Browser version metadata. final StringprotocolJson()The current devtools protocol definition, as a JSON string. final List<ChromeDPTarget>targets()A list of all available websocket targets (e.g. final ChromeDPTargetnewTab(String url)Opens a new tab. final StringactivateTab(String targetId)Brings a page into the foreground (activates a tab). final StringcloseTab(String targetId)Closes the target page identified by targetId. final UnitcloseAllTargets()Closes all targets. final ChromeBrowserSessionwebSocket()Opens a web socket connection to interact with the browser target (root session, without session ID). -
-
Method Detail
-
version
final ChromeVersion version()
Browser version metadata.
-
protocolJson
final String protocolJson()
The current devtools protocol definition, as a JSON string.
-
targets
final List<ChromeDPTarget> targets()
A list of all available websocket targets (e.g. browser tabs).
-
newTab
@Deprecated(message = "Prefer richer API via web socket", replaceWith = @ReplaceWith(imports = {}, expression = "webSocket().attachToNewPage(url)")) final ChromeDPTarget newTab(String url)
Opens a new tab. Responds with the websocket target data for the new tab.
-
activateTab
final String activateTab(String targetId)
Brings a page into the foreground (activates a tab).
-
closeAllTargets
final Unit closeAllTargets()
Closes all targets.
-
webSocket
final ChromeBrowserSession webSocket()
Opens a web socket connection to interact with the browser target (root session, without session ID).
The returned ChromeBrowserSession only provides a limited subset of the possible operations, because it is attached to the default browser target, not a page target. To attach to a specific target using the same underlying web socket connection, call ChromeBrowserSession.attachToPage or ChromeBrowserSession.attachToNewPage.
Note that you're responsible for closing the web socket by calling ChromeBrowserSession.close, or indirectly by calling (
use()). Note that calling close() oruse()on a derived ChromePageSession doesn't close the underlying web socket connection.
-
-
-
-