Package 

Class ChromeDPClient


  • 
    public final class ChromeDPClient
    
                        

    A 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, use a WebSocketClient and WebSocketClient.connectToChrome instead. A default web socket client can be created using defaultWebSocketClient.

    Chrome doesn't accept a Host header that is not an IP nor localhost, 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 Host header 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 the Host header to build these URLs, and it would be incorrect to keep this.

    • Constructor Summary

      Constructors 
      Constructor Description
      ChromeDPClient(String remoteDebugUrl, Boolean overrideHostHeader, WebSocketClient webSocketClient, HttpClient httpClient)
    • Method Summary

      Modifier and Type Method Description
      final ChromeVersion version() Browser version metadata.
      final String protocolJson() The current devtools protocol definition, as a JSON string.
      final List<ChromeDPTarget> targets() A list of all available websocket targets (e.g.
      final ChromeDPTarget newTab(String url) Opens a new tab.
      final String activateTab(String targetId) Brings a page into the foreground (activates a tab).
      final String closeTab(String targetId) Closes the target page identified by targetId.
      final Unit closeAllTargets() Closes all targets.
      final ChromeBrowserSession webSocket() Opens a web socket connection to interact with the browser target (root session, without session ID).
      • Methods inherited from class org.hildan.chrome.devtools.protocol.ChromeDPClient

        equals, hashCode, toString
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait