Class BrowserObservabilityRecorder

java.lang.Object
com.shaft.tools.io.internal.BrowserObservabilityRecorder

public final class BrowserObservabilityRecorder extends Object
Thread-local browser network, console, and capability metadata recorder for SHAFT trace artifacts.
  • Method Details

    • startNetwork

      public static BrowserObservabilityRecorder.NetworkExchange startNetwork(org.openqa.selenium.remote.http.HttpRequest request)
      Starts a network exchange and copies the request body so downstream filters can still read it.
      Parameters:
      request - browser HTTP request
      Returns:
      exchange handle, or a disabled handle when trace network capture is disabled
    • finishNetwork

      public static void finishNetwork(BrowserObservabilityRecorder.NetworkExchange exchange, org.openqa.selenium.remote.http.HttpResponse response, String failureReason)
      Finishes a network exchange and records a redacted trace event.
      Parameters:
      exchange - exchange handle returned from startNetwork(HttpRequest)
      response - browser HTTP response, or null on failure
      failureReason - safe failure reason
    • recordNetwork

      public static void recordNetwork(BrowserObservabilityRecorder.NetworkObservation observation)
      Records a browser network event for the current test thread.
      Parameters:
      observation - network exchange details
    • collectConsole

      public static void collectConsole(org.openqa.selenium.WebDriver driver)
      Collects Selenium browser logs into the console trace section.
      Parameters:
      driver - active driver, or null
    • recordConsole

      public static void recordConsole(String source, String level, String message, long timestamp)
      Records a browser console event for the current test thread.
      Parameters:
      source - log source
      level - log level
      message - log message
      timestamp - epoch timestamp in milliseconds
    • recordWarning

      public static void recordWarning(String source, String message)
      Records safe browser observability metadata for unsupported capabilities.
      Parameters:
      source - capability source
      message - warning message
    • drainWarnings

      public static List<String> drainWarnings()
      Returns and clears current-thread warnings.
      Returns:
      recorded warnings
    • snapshot

      Returns a read-only, 1-based snapshot of the current thread's observed network transactions without draining them, so a caller can list transactions repeatedly (for example an MCP tool answering separate "list" and "get by id" requests) without racing FailureTraceReporter's end-of-test drain of the same thread-local state.
      Returns:
      immutable snapshot of currently recorded network transactions, oldest first
    • drainNetworkHarJson

      public static String drainNetworkHarJson()
      Returns and clears current-thread network observations as a HAR-like JSON document.
      Returns:
      HAR-like network JSON
    • clear

      public static void clear()
      Clears current-thread browser observability state.