Class BrowserConn


  • public class BrowserConn
    extends java.lang.Object
    A Connection to a Browser, rather than an individual Page within the Browser.

    Field Extraction Behavior for PageConn, from a JsonObject

    Field isOptional throwOnNull
    id ❌ false ✅ true
    type ❌ false ✅ true
    title ✅ true ❌ false
    url ❌ false ✅ true
    description ✅ true ❌ false
    webSocketDebuggerUrl ❌ false ✅ true
    devtoolsFrontendUrl ✅ true ❌ false
    faviconUrl ✅ true ❌ false

    🔥 Why This Works

    Feature Explanation
    Predictable: You will never silently receive null on a required field.
    Traceable: If Chrome breaks compatibility, you'll get an exception pointing directly to it.
    Safe: Chrome Optional fields that disappear or return null won't break anything.

    This is exactly how you should structure a wrapper for an external spec you don't control — aggressive for connection-critical data, forgiving for decorative or diagnostic fields.

    💡 If Google changes their output?

    You'll know immediately — and you'll see exactly which field failed in a JsonPropMissingException or JsonNullObjException thanks to your excellent ReadJSON layer.


    Page originally drafted by ChatGPT on 2025-07-16.
    Edited and formatted for use in the Browser RDP Tool's documentation.



    • Field Detail

      • browser

        🡇     🗕  🗗  🗖
        public final java.lang.String browser
        The browser's identity string, typically in the format "Chrome/123.0.0.0". This value identifies the actual build and version of the running Chrome instance.
        Code:
        Exact Field Declaration Expression:
         public final String browser;
        
      • protocolVersion

        🡅  🡇     🗕  🗗  🗖
        public final java.lang.String protocolVersion
        The protocol version exposed by the Chrome DevTools Protocol. Usually in the format "1.3". Required for feature compatibility and command dispatch matching.
        Code:
        Exact Field Declaration Expression:
         public final String protocolVersion;
        
      • userAgent

        🡅  🡇     🗕  🗗  🗖
        public final java.lang.String userAgent
        The full User-Agent string as reported by the browser. This is typically sent with HTTP requests and can be used for debugging or emulating different clients.
        Code:
        Exact Field Declaration Expression:
         public final String userAgent;
        
      • v8Version

        🡅  🡇     🗕  🗗  🗖
        public final java.lang.String v8Version
        The version string for the embedded V8 JavaScript engine. Informational only; useful for diagnostics or feature expectations tied to ECMAScript support.
        Code:
        Exact Field Declaration Expression:
         public final String v8Version;
        
      • webkitVersion

        🡅  🡇     🗕  🗗  🗖
        public final java.lang.String webkitVersion
        The WebKit version string used in the rendering engine. Like the V8 version, this is generally used for diagnostic purposes, especially in rendering bug analysis.
        Code:
        Exact Field Declaration Expression:
         public final String webkitVersion;
        
      • webSocketDebuggerUrl

        🡅  🡇     🗕  🗗  🗖
        public final java.lang.String webSocketDebuggerUrl
        The WebSocket Debugger URL used to initiate communication with the Chrome DevTools Protocol. This URL is required to establish a live debugging session or automation bridge with the browser instance.
        Code:
        Exact Field Declaration Expression:
         public final String webSocketDebuggerUrl;
        
    • Method Detail

      • createSender

        🡅  🡇     🗕  🗗  🗖
        public WebSocketSender createSender​
                    (java.util.function.Consumer<BrowserEvent> eventHandler,
                     java.util.function.Consumer<RDPError> rdpErrorHandler,
                     java.util.function.Consumer<BrowserError> browserErrorHandler)
                throws java.io.IOException,
                       WebSocketException
        
        Creates a WebSocketSender connected to the webSocketDebuggerUrl for this tab. This URL is the endpoint that speaks the Chrome DevTools Protocol (CDP).
        Parameters:
        eventHandler - Provide any Java-Consumer>BrowserEvent>. Null may not be passed to this parameter, or NullPointerException throws.
        rdpErrorHandler - Accepts any Java-Consumer<RDPError>. If null is passed to this parameter, then a default {@code 'No Op'} handler will be used for constructing the WebSocketSender instance.

        Error Type: This Error-Handler will accept notices about errors which may or may not have occured with the underlying transport mechanism. The types of errors which would, conceivably, be sent to this handler are exactly the type of errors which shouldn't ever occurr. In essence, this parameter is an "assertion failure" notice receiver to which Web-Socket Errors are transmitted. Web-Socket Connection Failures should be Unreachable, but since I/O Problems can always be an issue, this Handler is provided even though its messages should not be possible in a properly debugged environment.
        browserErrorHandler - Accepts any Java-Consumer<BrowserError>. If null is passed to this parameter, then a default 'No Op' handler will be used for constructing the WebSocketSender instance.

        Error Type: This Error-Handler will accept notices about errors which have been broadcast by the Web-Browser, across the Web-Sockets Connection, back to this API. These are Browser-Layer Errors, received by Web-Socket Message Frames. These type of Errors are not Transport-Layer, Web-Socket Errors.
        Throws:
        java.io.IOException
        WebSocketException
        Code:
        Exact Method Body:
         return new WebSocketSender
             (this.webSocketDebuggerUrl, eventHandler, rdpErrorHandler, browserErrorHandler);
        
      • getBrowserConn

        🡅  🡇         External-Java:    🗕  🗗  🗖
        public static BrowserConn getBrowserConn​(java.lang.Integer port,
                                                 boolean quiet)
        Retrieves the WebSocketDebugger URL for the main browser instance. This queries /json/version and parses the result into an instance.
        Parameters:
        port - The DevTools port Chrome is listening on (default is 9222 if null).
        quiet - If false, debug output is printed to the console.
        Returns:
        A BrowserConn instance representing the browser-level connection.
        Code:
        Exact Method Body:
         return BCBuilder.getBrowserConn(port, quiet);
        
      • toString

        🡅  🡇         External-Java:    🗕  🗗  🗖
        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
        Code:
        Exact Method Body:
         return BCHelper.toString(this);
        
      • hashCode

        🡅  🡇         External-Java:    🗕  🗗  🗖
        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
        Code:
        Exact Method Body:
         return BCHelper.hashCode(this);
        
      • equals

        🡅  🡇         External-Java:    🗕  🗗  🗖
        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
        Code:
        Exact Method Body:
         return BCHelper.equals(this, o);