CdpHar

class · namespace z3n7 · source Traffic/CdpHar.cs

public sealed class CdpHar : IDisposable

HAR recorder that talks to the instance browser over its own DevTools endpoint (the browser writes the port to <user-data-dir>\DevToolsActivePort). Does not depend on Tab.GetTraffic. Records only what happens after Start().

Properties

Count

public int Count { get; }

source

Number of recorded entries.

DevToolsPort

public int DevToolsPort { get; }

source

DevTools port of the browser.

IsAlive

public bool IsAlive { get; }

source

Whether the DevTools connection is open.

LastError

public string LastError { get; }

source

Last error of the background receive loop, or null.

Methods

Clear

public void Clear()

source

Forgets all recorded entries.

Connect

public static CdpHar Connect(int devToolsPort)

source

Recorder bound to an explicit DevTools port (not registered per instance).

Dispose

public void Dispose()

source

Closes the DevTools connection.

For

public static CdpHar For(Instance instance)

source

Running recorder for this instance or null.

ResolveDevToolsPort

public static int ResolveDevToolsPort(Instance instance)

source

Finds the DevTools port of the instance's browser from DevToolsActivePort files: the instance profile folder, the ProjectMaker browser folder and ZennoPoster's Trash\Profiles\*. The profile's own port wins when it is live; otherwise the only live candidate; otherwise the one whose page URL equals ActiveTab.URL.

Returns: The port. Throws InvalidOperationException when no live browser or several matching ones are found.

Save

public int Save(string path, string urlRegex = null, int waitBodiesMs = 3000)

source

Writes the recorded traffic to a HAR 1.2 file (missing folders are created, an existing file is replaced).

Parameter Description
path Target file.
urlRegex Case-insensitive regex the URL must match; null keeps everything.
waitBodiesMs How long to wait for response bodies still being fetched.

Returns: Number of entries written.

Start

public static CdpHar Start(Instance instance)

source

Starts (or returns the running) recorder for this instance.

Stop

public static void Stop(Instance instance)

source

Stops and forgets the recorder of this instance, if any.

Fields

CommandTimeoutMs

public int CommandTimeoutMs;

source

Timeout for connecting and for each DevTools command, ms.

MaxBodyBytes

public long MaxBodyBytes;

source

Response bodies larger than this (encoded size) are not fetched.

MaxEntries

public int MaxEntries;

source

Most entries kept; the oldest are dropped beyond it.