Package Torello.Browser
Class BrowserConn
- java.lang.Object
-
- Torello.Browser.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 aJsonObject
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 aJsonPropMissingException
orJsonNullObjException
thanks to your excellentReadJSON
layer.
Page originally drafted by ChatGPT on 2025-07-16.
Edited and formatted for use in the Browser RDP Tool's documentation.
Hi-Lited Source-Code:- View Here: Torello/Browser/BrowserConn.java
- Open New Browser-Tab: Torello/Browser/BrowserConn.java
File Size: 6,366 Bytes Line Count: 148 '\n' Characters Found
-
-
Field Summary
Fields Modifier and Type Field Description String
browser
String
protocolVersion
String
userAgent
String
v8Version
String
webkitVersion
String
webSocketDebuggerUrl
-
Constructor Summary
Constructors Constructor Description BrowserConn(String browser, String protocolVersion, String userAgent, String v8Version, String webkitVersion, String webSocketDebuggerUrl)
BrowserConn(JsonObject jo)
-
Method Summary
Create Browser WebSocket Sender Modifier and Type Method Description WebSocketSender
createSender(Consumer<BrowserEvent> eventHandler, Consumer<RDPError> rdpErrorHandler, Consumer<BrowserError> browserErrorHandler)
Creates aWebSocketSender
connected to thewebSocketDebuggerUrl
for this tab.Static-Getter: Creates an Instance of this Class Modifier and Type Method Description static BrowserConn
getBrowserConn(Integer port, boolean quiet)
Retrieves the WebSocketDebugger URL for the main browser instance.Methods: class java.lang.Object Modifier and Type Method Description boolean
equals(Object o)
int
hashCode()
String
toString()
Methods: interface java.lang.Cloneable Modifier and Type Method Description BrowserConn
clone()
-
-
-
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 fullUser-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;
-
-
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)
-
BrowserConn
public BrowserConn(JsonObject jo)
-
-
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 aWebSocketSender
connected to thewebSocketDebuggerUrl
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, orNullPointerException
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 theWebSocketSender
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 theWebSocketSender
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
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 ifnull
).quiet
- Iffalse
, 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
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
- Code:
- Exact Method Body:
return BCHelper.toString(this);
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
- Code:
- Exact Method Body:
return BCHelper.hashCode(this);
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
- Code:
- Exact Method Body:
return BCHelper.equals(this, o);
-
clone
public BrowserConn clone()
- Overrides:
clone
in classjava.lang.Object
- Code:
- Exact Method Body:
return BCHelper.clone(this);
-
-