feat: add network har start/stop command for HAR 1.2 export (#874)

Expose HAR recording as a CLI subcommand under the existing `network`
command so users can capture and export network traffic without a
separate tool or opening the browser twice.

- Parse `network har start` and `network har stop [path]` in commands.rs
- Enrich HarEntry with request/response headers, timestamps, status text,
  resource type, HTTP version, and body sizes from CDP events
- Produce HAR 1.2 output with creator/browser metadata, query strings,
  and proper header arrays compatible with Chrome DevTools HAR viewer
- Auto-generate output path under ~/.agent-browser/tmp/har/ when omitted
- Add har_stop to skip_launch list so export works without a live browser
- Update help text, README, docs site, SKILL.md, and security policy docs
- Add unit tests for parsing, HAR entry serialization, and stop behavior
This commit is contained in:
Chris Yang
2026-03-17 09:02:39 -05:00
committed by GitHub
parent 663e10355a
commit 8dd012f4fd
9 changed files with 536 additions and 34 deletions
+13 -3
View File
@@ -456,13 +456,16 @@ pub fn print_response_with_opts(resp: &Response, action: Option<&str>, opts: &Ou
println!("{} {}", color::success_indicator(), label);
return;
}
// Recording start (has "started" field)
// Started actions (profiling, HAR, recording)
if let Some(started) = data.get("started").and_then(|v| v.as_bool()) {
if started {
match action {
Some("profiler_start") => {
println!("{} Profiling started", color::success_indicator());
}
Some("har_start") => {
println!("{} HAR recording started", color::success_indicator());
}
_ => {
if let Some(path) = data.get("path").and_then(|v| v.as_str()) {
println!("{} Recording started: {}", color::success_indicator(), path);
@@ -591,9 +594,12 @@ pub fn print_response_with_opts(resp: &Response, action: Option<&str>, opts: &Ou
data.get("eventCount").and_then(|c| c.as_u64()).unwrap_or(0)
),
"har_stop" => println!(
"{} HAR saved to {}",
"{} HAR saved to {} ({} requests)",
color::success_indicator(),
color::green(path)
color::green(path),
data.get("requestCount")
.and_then(|c| c.as_u64())
.unwrap_or(0)
),
"download" | "waitfordownload" => println!(
"{} Download saved to {}",
@@ -1721,6 +1727,7 @@ Subcommands:
requests [options] List captured requests
--clear Clear request log
--filter <pattern> Filter by URL pattern
har <start|stop> [path] Record and export a HAR file
Global Options:
--json Output as JSON
@@ -1733,6 +1740,8 @@ Examples:
agent-browser network requests
agent-browser network requests --filter "api"
agent-browser network requests --clear
agent-browser network har start
agent-browser network har stop ./capture.har
"##
}
@@ -2516,6 +2525,7 @@ Network: agent-browser network <action>
route <url> [--abort|--body <json>]
unroute [url]
requests [--clear] [--filter <pattern>]
har <start|stop> [path]
Storage:
cookies [get|set|clear] Manage cookies (set supports --url, --domain, --path, --httpOnly, --secure, --sameSite, --expires)