Class BrowserError

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<BrowserError>

    public class BrowserError
    extends java.lang.Object
    implements java.io.Serializable, java.lang.Comparable<BrowserError>

    Represents an Error Sent by the Chrome Browser over WebSocket

    This class encapsulates error messages originating from the browser itself — not from the Java side, and not from transport-layer failures (like network disconnects or malformed JSON). These errors are generated by the browser's internal logic during its processing of a CDP (Chrome DevTools Protocol) command.

    When the browser receives a CDP command that it cannot process correctly — due to invalid parameters, internal issues, or unrecognized method calls — it responds over the WebSocket channel with a structured error message. This message includes both an error code and a textual message describing the problem. This class captures and stores that information in a structured way, so it can be logged, analyzed, or acted upon.

    Importantly, this error is not thrown as a Java exception, nor does it represent a problem in the Java-side tooling (e.g., parsing, socket I/O, etc.). It is an intentional error response issued by the browser itself, indicating that a CDP command could not be fulfilled.


    Registering a Handler:
    To receive instances of this error class, a handler must be registered at the time you create your WebSocketSender using one of the createSender(...) methods found in either BrowserConn or PageConn. These methods allow you to provide lambda handlers or consumer functions for error callbacks. Without explicitly setting a handler for this error type, you will never see these errors—they will be silently discarded or ignored by the internal infrastructure.

    Each of the three CDP error/response types — RDPError, BrowserError, and BrowserEvent — has its own dedicated handler. These are supplied as Consumer arguments to createSender(...), and any logic you wish to perform in response to these events must be defined there. The WebSocketSender will invoke these handlers automatically whenever it receives a message of the corresponding kind.
    See Also:
    Serialized Form


    • Field Summary

       
      Serializable ID
      Modifier and Type Field Description
      protected static long serialVersionUID
       
      Instance Fields
      Modifier and Type Field Description
      int code
      The numeric error code assigned by the browser for this error.
      String commandName
      If this error was generated by a known Command, then the name of that command is saved into this field.
      Domains domain
      If this error was generated by a known Domain, then it will be savied into this field.
      String message
      The textual description of the error as provided by Chrome.
      String requestJSONString
      The Json used to build the command.
    • Constructor Summary

      Constructors 
      Constructor Description
      BrowserError​(int code, String message)  
    • Method Summary

       
      Methods: class java.lang.Object
      Modifier and Type Method Description
      boolean equals​(Object other)  
      int hashCode()  
      String toString()  
       
      Methods: interface java.lang.Comparable
      Modifier and Type Method Description
      int compareTo​(BrowserError error)  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • serialVersionUID

        🡇     🗕  🗗  🗖
        protected static final long serialVersionUID
        This fulfils the SerialVersion UID requirement for all classes that implement Java's interface java.io.Serializable. Using the Serializable Implementation 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;
        
      • code

        🡅  🡇     🗕  🗗  🗖
        public final int code
        The numeric error code assigned by the browser for this error.

        This code is defined internally by the Browser and often (but not always) maps to specific protocol-related error conditions such as "Invalid Parameters", "Target Not Found", or "Method Not Implemented." While not formally documented in all cases, the code can be used to categorize and respond to common failure cases.
        Code:
        Exact Field Declaration Expression:
         public final int code;
        
      • message

        🡅  🡇     🗕  🗗  🗖
        public final java.lang.String message
        The textual description of the error as provided by Chrome.

        This message is intended for human readability and often contains hints or clues about why the CDP command failed. It may mention an unsupported method name, a missing argument, or some kind of runtime condition that prevented the browser from fulfilling the request.

        While the message is not guaranteed to follow a fixed schema, it is often specific enough to help diagnose problems—especially when debugging command payloads or execution timing.
        Code:
        Exact Field Declaration Expression:
         public final String message;
        
      • domain

        🡅  🡇     🗕  🗗  🗖
        public final Domains domain
        If this error was generated by a known Domain, then it will be savied into this field. If the name is not known, this field will be null.
        Code:
        Exact Field Declaration Expression:
         public final Domains domain;
        
      • commandName

        🡅  🡇     🗕  🗗  🗖
        public final java.lang.String commandName
        If this error was generated by a known Command, then the name of that command is saved into this field. If the name is not known, this field will be null.
        Code:
        Exact Field Declaration Expression:
         public final String commandName;
        
      • requestJSONString

        🡅  🡇     🗕  🗗  🗖
        public final java.lang.String requestJSONString
        The Json used to build the command.
        Code:
        Exact Field Declaration Expression:
         public final String requestJSONString;
        
    • Method Detail

      • toString

        🡅  🡇     🗕  🗗  🗖
        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
        Code:
        Exact Method Body:
         final String ret =
             "BrowserError Received:\n" +
             "{\n" +
             "    Code:    " + this.code + '\n' +
             "    Message: " + this.message + '\n';
        
         if (this.domain == null) return ret + '}';
        
         return ret + 
             "    Domain:  " + this.domain.getPackageName() + '\n' +
             "    Command: " + this.commandName + 
             '}';
        
      • hashCode

        🡅  🡇     🗕  🗗  🗖
        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
        Code:
        Exact Method Body:
         return this.code + this.message.hashCode();
        
      • equals

        🡅  🡇     🗕  🗗  🗖
        public boolean equals​(java.lang.Object other)
        Overrides:
        equals in class java.lang.Object
        Code:
        Exact Method Body:
         if (this == other) return true;
         if (other == null) return false;
        
         if (this.getClass() != other.getClass()) return false;
        
         final BrowserError o = (BrowserError) other;
        
         return
                 (this.code == o.code)
             &&  Objects.equals(this.message, o.message)
             &&  Objects.equals(this.domain, o.domain)
             &&  Objects.equals(this.commandName, o.commandName);
        
      • compareTo

        🡅     🗕  🗗  🗖
        public int compareTo​(BrowserError error)
        Specified by:
        compareTo in interface java.lang.Comparable<BrowserError>
        Code:
        Exact Method Body:
         if (this.code != error.code)
             return this.code - error.code;
        
         return this.message.compareTo(error.message);