Skip to content

Commit 55aa0c9

Browse files
DJRHailspatch-stack-bot[bot]
authored andcommitted
fix: prevent tab_switch from printing "Browser closed"
The condition `data.get("tabId").is_some()` matched any response containing tabId, including tab_switch. Now only checks for `data.get("closed").is_some()` and adds a dedicated tab_switch output handler showing "Switched to tab [id] (url)".
1 parent baf94bd commit 55aa0c9

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

cli/src/commands.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2862,7 +2862,7 @@ mod tests {
28622862
#[test]
28632863
fn test_network_har_requires_subcommand() {
28642864
let result = parse_command(&args("network har"), &default_flags());
2865-
assert!(matches!(result, Err(ParseError::MissingArguments { .. }));
2865+
assert!(matches!(result, Err(ParseError::MissingArguments { .. })));
28662866
}
28672867

28682868
#[test]

cli/src/output.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,26 @@ pub fn print_response_with_opts(resp: &Response, action: Option<&str>, opts: &Ou
401401
}
402402
return;
403403
}
404+
// Tab switch
405+
if action == Some("tab_switch") {
406+
if let Some(tab_id) = data.get("tabId").and_then(|v| v.as_i64()) {
407+
if let Some(url) = data.get("url").and_then(|v| v.as_str()) {
408+
println!(
409+
"{} Switched to tab [{}] ({})",
410+
color::success_indicator(),
411+
tab_id,
412+
url
413+
);
414+
} else {
415+
println!(
416+
"{} Switched to tab [{}]",
417+
color::success_indicator(),
418+
tab_id
419+
);
420+
}
421+
return;
422+
}
423+
}
404424
// New tab/window
405425
if let Some(tab_id) = data.get("tabId").and_then(|v| v.as_i64()) {
406426
if let Some(total) = data.get("total").and_then(|v| v.as_i64()) {
@@ -556,7 +576,7 @@ pub fn print_response_with_opts(resp: &Response, action: Option<&str>, opts: &Ou
556576
return;
557577
}
558578
// Closed (browser or tab)
559-
if data.get("closed").is_some() || data.get("tabId").is_some() {
579+
if data.get("closed").is_some() {
560580
let label = match action {
561581
Some("tab_close") => {
562582
if let Some(closed_id) = data.get("tabId").and_then(|v| v.as_i64()) {

0 commit comments

Comments
 (0)