Class BrowserNetworkInterceptor

java.lang.Object
com.shaft.gui.browser.internal.BrowserNetworkInterceptor
All Implemented Interfaces:
AutoCloseable

public class BrowserNetworkInterceptor extends Object implements AutoCloseable
Owns browser network interception rules for one WebDriver session.
  • Constructor Summary

    Constructors
    Constructor
    Description
    BrowserNetworkInterceptor(org.openqa.selenium.WebDriver driver)
    Creates a browser network interceptor backed by Selenium DevTools.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Adds a rule and activates it for the current browser session.
    void
    Clears all registered rules.
    void
    Clears rules and removes the Selenium network filter during driver teardown.
    boolean
    Reports whether this interceptor has one or more mock/validate rules registered.
    boolean
    Releases this interceptor's DevTools network filter so another owner (for example a dedicated API-capture recorder that composes the same trace/HAR observation inside its own filter) can become the sole registrant for this driver.
    boolean
    Starts passive network observation without changing existing mock/assert/verify rules.

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • BrowserNetworkInterceptor

      public BrowserNetworkInterceptor(org.openqa.selenium.WebDriver driver)
      Creates a browser network interceptor backed by Selenium DevTools.
      Parameters:
      driver - the active WebDriver session
  • Method Details

    • addRule

      public void addRule(BrowserNetworkInterceptionRule rule)
      Adds a rule and activates it for the current browser session.
      Parameters:
      rule - rule to add
    • startObserving

      public boolean startObserving()
      Starts passive network observation without changing existing mock/assert/verify rules.
      Returns:
      true when observation started
    • hasActiveRules

      public boolean hasActiveRules()
      Reports whether this interceptor has one or more mock/validate rules registered.

      Callers that want to take over sole ownership of the DevTools network filter (for example a dedicated API-capture recorder) must not do so while rules are registered here: replacing this interceptor's filter would silently drop active mocking/validation behavior with no warning to the caller that registered those rules.

      Returns:
      true when at least one interception rule is registered
    • releaseForHandoff

      public boolean releaseForHandoff()
      Releases this interceptor's DevTools network filter so another owner (for example a dedicated API-capture recorder that composes the same trace/HAR observation inside its own filter) can become the sole registrant for this driver.

      Only safe to call when hasActiveRules() is false: this method does not clear registered rules, and calling it while rules exist would leave them registered here but inactive on the driver, silently breaking any mock/validate behavior callers still expect.

      Returns:
      true when passive observation was active and has been released
    • clear

      public void clear()
      Clears all registered rules. Passive trace observation remains active when it was started for the session.
    • close

      public void close()
      Clears rules and removes the Selenium network filter during driver teardown.
      Specified by:
      close in interface AutoCloseable