Class CaptureNetworkRecorder
- All Implemented Interfaces:
AutoCloseable
Filter
(the same NetworkInterceptor-backed mechanism BrowserNetworkInterceptor uses),
classifies each transaction, applies asset/first-party/glob filters and a transaction cap,
scrubs secret headers via SecretHeaderReplacer, persists bodies through
NetworkBodyStore, and emits one CaptureNetworkRecorder.RecordedTransaction per recorded transaction to
the session sink, which is responsible for wrapping it into a first-class
CaptureEvent.NetworkEvent with a properly sequenced EventContext.
This recorder is the sole owner of the DevTools network filter for its session. Selenium's
NetworkInterceptor registration is a single-slot replace, not a compose/stack: whichever
interceptor registers last on a given driver silently wins, and the other's filter goes dead with
no warning. com.shaft.driver.internal.DriverFactory.DriverFactoryHelper may already have
started a BrowserNetworkInterceptor-owned NetworkInterceptor for passive trace/HAR
observation on the same driver whenever shaft.trace.enabled and
shaft.trace.includeNetwork are true -- a global property independent of API
capture. Before installing its own filter, start() calls
DriverFactoryHelper.releaseBrowserNetworkObservationForHandoff(WebDriver) so that prior
passive observer relinquishes the DevTools filter first; this recorder's own filter composes
BrowserObservabilityRecorder.startNetwork(HttpRequest) and
BrowserObservabilityRecorder.finishNetwork(BrowserObservabilityRecorder.NetworkExchange, HttpResponse, String)
so trace/HAR capture keeps working without a second interceptor. When the driver's
BrowserNetworkInterceptor instead has mock/validate rules registered, handoff is refused
(replacing that filter would silently break those rules); in that case this recorder logs a
one-time warning and does not register its own filter, avoiding the double-registration entirely.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordOne redacted, replay-safe network transaction observed by this recorder, ready to be wrapped into aCaptureEvent.NetworkEventonce the caller assigns anEventContext(sequence, page, timestamp). -
Constructor Summary
ConstructorsConstructorDescriptionCaptureNetworkRecorder(org.openqa.selenium.WebDriver driver, Path bodiesDirectory, NetworkCaptureOptions options, String sessionId, Supplier<String> currentPageUrlSupplier, Consumer<CaptureNetworkRecorder.RecordedTransaction> sink, Consumer<String> warn) Creates a network recorder for one browser session. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Stops network capture and releases the DevTools filter exactly once.Returns the most recently observed endpoints, most-recent-first, bounded to a small preview.static booleanmatchesGlob(String url, String glob) Matches a URL against a Playwright-style glob (used for both live network include/exclude filters here and HAR-export filtering inManagedCaptureRecorder).booleanstart()Starts network capture when the driver supports DevTools.intReturns the number of network transactions recorded so far.
-
Constructor Details
-
CaptureNetworkRecorder
public CaptureNetworkRecorder(org.openqa.selenium.WebDriver driver, Path bodiesDirectory, NetworkCaptureOptions options, String sessionId, Supplier<String> currentPageUrlSupplier, Consumer<CaptureNetworkRecorder.RecordedTransaction> sink, Consumer<String> warn) Creates a network recorder for one browser session.- Parameters:
driver- active WebDriver sessionbodiesDirectory- directory used to persist request/response bodiesoptions- network capture filtering and body-capture optionssessionId- owning capture session identifier, used for deterministic secret-ref derivationcurrentPageUrlSupplier- supplies the last-known top-level page URL for first-party classification andinitiatorPageUrltagging; must be a non-blocking read (seecreateFilter()for why it must never call back into the WebDriver session)sink- destination for each recorded, redacted network transactionwarn- destination for safe one-time warnings
-
-
Method Details
-
start
public boolean start()Starts network capture when the driver supports DevTools. Gates onHasDevTools; when unsupported, records a warning and leaves UI-only capture unaffected.Before installing its own DevTools network filter, this method asks
DriverFactoryHelperto release any passive trace/HAR observer it already registered on this driver, so this recorder becomes the sole interceptor owner instead of silently racing with and replacing it (or being replaced by it). When the driver'sBrowserNetworkInterceptorinstead has mock/validate rules registered, the handoff is refused; this method then logs a one-time warning and does not register a filter, so API capture is skipped rather than double-registering and breaking those rules.- Returns:
truewhen the network filter was registered
-
transactionCount
public int transactionCount()Returns the number of network transactions recorded so far.- Returns:
- recorded transaction count
-
lastEndpoints
-
close
public void close()Stops network capture and releases the DevTools filter exactly once.- Specified by:
closein interfaceAutoCloseable
-
matchesGlob
Matches a URL against a Playwright-style glob (used for both live network include/exclude filters here and HAR-export filtering inManagedCaptureRecorder).- Parameters:
url- URL to testglob- glob pattern; a blank glob never matches- Returns:
truewhen the URL matches the glob
-