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; }
Number of recorded entries.
DevToolsPort
public int DevToolsPort { get; }
DevTools port of the browser.
IsAlive
public bool IsAlive { get; }
Whether the DevTools connection is open.
LastError
public string LastError { get; }
Last error of the background receive loop, or null.
Methods
Clear
public void Clear()
Forgets all recorded entries.
Connect
public static CdpHar Connect(int devToolsPort)
Recorder bound to an explicit DevTools port (not registered per instance).
Dispose
public void Dispose()
Closes the DevTools connection.
For
public static CdpHar For(Instance instance)
Running recorder for this instance or null.
ResolveDevToolsPort
public static int ResolveDevToolsPort(Instance instance)
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)
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)
Starts (or returns the running) recorder for this instance.
Stop
public static void Stop(Instance instance)
Stops and forgets the recorder of this instance, if any.
Fields
CommandTimeoutMs
public int CommandTimeoutMs;
Timeout for connecting and for each DevTools command, ms.
MaxBodyBytes
public long MaxBodyBytes;
Response bodies larger than this (encoded size) are not fetched.
MaxEntries
public int MaxEntries;
Most entries kept; the oldest are dropped beyond it.