Package Torello.Browser
Class BrowserConn
- java.lang.Object
-
- Torello.Browser.BrowserConn
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,java.lang.Comparable<BrowserConn>
public class BrowserConn extends java.lang.Object implements java.io.Serializable, java.lang.Comparable<BrowserConn>, java.lang.Cloneable
A Connection to a Browser, rather than an individual Page within the Browser.
Represents a snapshot of metadata returned from Chrome’s/json/versionEnd-Point. This includes protocol versioning, V8 details, and the rootWebSocketURLfor establishing DevTools sessions.
Although this class offers a public constructor, the recommended way to build an instance is via thestaticmethod:getBrowserConn. This instance contains a few informational fields that were scraped from the Json-Response to the above mentioned Chrome response object.
AWebSocketSenderInstance:
To begin sending CDP commands, it is mandatory to obtain an instance of theWebSocketSenderclass which has been connected to a Web Browser. This instance should be passed as the sender to any of the available API methods offered by the Domain Classes in the packagesBrowserAPIand or the classes inJavaScriptAPI. You should review the methods exported by each of the domains and classes within those packages, and note that theScriptobjects returned by them expose anScript.exec(WebSocketSender)method.
Obtaining theWebSocketSenderinstance can be achieved by invokingBrowserConn.createSender, a method offered by this class. This method initializes aWebSocketSenderwhich is connected to the associatedwebSocketDebuggerUrl. That sender can be used to make invocations into all CDP Domains.
The individual fields exported by this class are documented below, and within their respective documentation. This class, itself, is largely a structured data holder with minimal logic. Mostly, it parses the Json which is returned by the Web-Browser endpoint/json/version.
Issuing Commands to a Browser:
The most important aspect to understand when it comes to using the classesBrowserConn,PageConn, andWebSocketSenderis what needs to be done in order to start sending commands to the browser over a Web-Socket using the Browser's Remote Debug Port API. These are the steps, listed below, that a programmer should take to begin using the Java-Script and Browser API Tools offered by these pacakges- Ensure that Chrome (or another Chromium-compatible browser) is installed.
- Start the browser with its RDP (Remote Debug Port) feature enabled.
Note: It is acceptable to start a full graphical browser rather than a headless one — as long as RDP is active.
- Successfully extract either a
BrowserConnor aPageConninstance by invoking their respectivegetmethods.
- Invoke either
BrowserConn.createSenderorPageConn.createSenderto retrieve an instance ofWebSocketSender.
This instance can be passed to anyScriptobject generated by the domain class methods in theBrowserAPIorJavaScriptAPIpackages.
- This package provides example classes demonstrating how to establish connections with either a headless or full browser, and how to issue commands using the domain classes.
- See Also:
- Serialized Form
Hi-Lited Source-Code:- View Here: Torello/Browser/BrowserConn.java
- Open New Browser-Tab: Torello/Browser/BrowserConn.java
File Size: 8,803 Bytes Line Count: 195 '\n' Characters Found
-
-
Field Summary
Serializable ID Modifier and Type Field Description protected static longserialVersionUIDInstance Fields Modifier and Type Field Description StringbrowserStringprotocolVersionStringuserAgentStringv8VersionStringwebkitVersionStringwebSocketDebuggerUrl
-
Constructor Summary
Constructors Constructor Description BrowserConn(String browser, String protocolVersion, String userAgent, String v8Version, String webkitVersion, String webSocketDebuggerUrl)Constructs an instance of this type.BrowserConn(JsonObject jo)
-
Method Summary
Create Browser WebSocket Sender Modifier and Type Method Description WebSocketSendercreateSender(ConnRecord connRec)Creates aWebSocketSenderconnected to thewebSocketDebuggerUrlfor this tab.Static-Getter: Creates an Instance of this Class Modifier and Type Method Description static BrowserConngetBrowserConn(Integer port, boolean quiet)Retrieves the WebSocketDebugger URL for the main browser instance.Methods: class java.lang.Object Modifier and Type Method Description booleanequals(Object o)inthashCode()StringtoString()Methods: interface java.lang.Comparable Modifier and Type Method Description intcompareTo(BrowserConn other)Methods: interface java.lang.Cloneable Modifier and Type Method Description BrowserConnclone()
-
-
-
Field Detail
-
serialVersionUID
protected static final long serialVersionUID
This fulfils the SerialVersion UID requirement for all classes that implement Java'sinterface java.io.Serializable. Using theSerializableImplementation offered by java is very easy, and can make saving program state when debugging a lot easier. It can also be used in place of more complicated systems like "hibernate" to store data as well.- See Also:
- Constant Field Values
- Code:
- Exact Field Declaration Expression:
protected static final long serialVersionUID = 1;
-
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 fullUser-Agentstring 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;
-
-
Constructor Detail
-
BrowserConn
public BrowserConn(java.lang.String browser, java.lang.String protocolVersion, java.lang.String userAgent, java.lang.String v8Version, java.lang.String webkitVersion, java.lang.String webSocketDebuggerUrl)
Constructs an instance of this type.- Throws:
java.lang.NullPointerException- if'webSocketDebuggerUrl'is passed null.- Code:
- Exact Constructor Body:
Objects.requireNonNull(webSocketDebuggerUrl, "webSocketDebuggerUrl is null"); this.browser = browser; this.protocolVersion = protocolVersion; this.userAgent = userAgent; this.v8Version = v8Version; this.webkitVersion = webkitVersion; this.webSocketDebuggerUrl = webSocketDebuggerUrl;
-
BrowserConn
public BrowserConn(JsonObject jo)
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, the programmer will receive 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?
The excellentReadJSONlayer would immediately generate either aJsonPropMissingExceptionorJsonNullObjExceptionallowing the programmer to know eactly which field has failed.
Page originally drafted by ChatGPT on 2025-07-16.
Edited and formatted for use in Chrome DevTools Protocol Documentation.- Parameters:
jo- The exactJsonObjectthat was generated by querying the HTTP End-Point/json/version.- See Also:
ReadJSON.getString(JsonObject, String, boolean, boolean)- Code:
- Exact Constructor Body:
this.browser = ReadJSON.getString(jo, "Browser", false, true); this.protocolVersion = ReadJSON.getString(jo, "Protocol-Version", false, true); this.userAgent = ReadJSON.getString(jo, "User-Agent", false, true); this.v8Version = ReadJSON.getString(jo, "V8-Version", true, false); this.webkitVersion = ReadJSON.getString(jo, "WebKit-Version", true, false); this.webSocketDebuggerUrl = ReadJSON.getString(jo, "webSocketDebuggerUrl", false, true);
-
-
Method Detail
-
createSender
public WebSocketSender createSender(ConnRecord connRec) throws java.io.IOException, WebSocketException
Creates aWebSocketSenderconnected to thewebSocketDebuggerUrlfor this tab. This URL is the endpoint that speaks the Chrome DevTools Protocol (CDP).- Parameters:
connRec- Messaging settings for this connection- Throws:
java.io.IOExceptionWebSocketException- Code:
- Exact Method Body:
return new WebSocketSender(this.webSocketDebuggerUrl, connRec);
-
getBrowserConn
public static BrowserConn getBrowserConn(java.lang.Integer port, boolean quiet)
Retrieves the WebSocketDebugger URL for the main browser instance. This queries/json/versionand parses the result into an instance.- Parameters:
port- The DevTools port Chrome is listening on (default is 9222 ifnull).quiet- Iffalse, debug output is printed to the console.- Returns:
- A
BrowserConninstance representing the browser-level connection. - Code:
- Exact Method Body:
return BCBuilder.getBrowserConn(port, quiet);
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object- Code:
- Exact Method Body:
return BCHelper.toString(this);
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object- Code:
- Exact Method Body:
return BCHelper.hashCode(this);
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object- Code:
- Exact Method Body:
return BCHelper.equals(this, o);
-
clone
public BrowserConn clone()
- Overrides:
clonein classjava.lang.Object- Code:
- Exact Method Body:
return BCHelper.clone(this);
-
compareTo
public int compareTo(BrowserConn other)
- Specified by:
compareToin interfacejava.lang.Comparable<BrowserConn>- Code:
- Exact Method Body:
return this.webSocketDebuggerUrl.compareTo(other.webSocketDebuggerUrl);
-
-