Package 

Class ChromeDPClient

  • All Implemented Interfaces:

    
    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, you can directly use HttpClient.chromeWebSocket.

    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.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      ChromeDPClient(String remoteDebugUrl, Boolean overrideHostHeader, HttpClient httpClient)
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Constructor Detail

      • ChromeDPClient

        ChromeDPClient(String remoteDebugUrl, Boolean overrideHostHeader, HttpClient httpClient)
    • Method Detail

      • protocolJson

         final String protocolJson()

        The current devtools protocol definition, as a JSON string.

      • 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.

      • 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() or use() on a derived ChromePageSession doesn't close the underlying web socket connection.