fix: detect externally opened tabs in --cdp mode (#1042)

* fix: detect externally opened tabs in --cdp mode (#1037)

Tabs opened outside of agent-browser (e.g. by the user or another CDP
client) were invisible to `tab list` because:

1. `Target.targetCreated` with chrome://newtab/ was filtered by
   `is_internal_chrome_target`, and the subsequent `targetInfoChanged`
   with the real URL could not update a target that was never tracked.

2. The background drain loop only ran when `request_tracking ||
   har_recording` was active, so target events between commands were
   silently dropped from the broadcast channel.

Fix: promote untracked targets in `targetInfoChanged` to new targets,
run the background drain unconditionally (guarded by browser presence),
and extract `apply_drained_events` to share target lifecycle processing
(attach, domain filter, iframe sessions) between execute_command and
the background drain.

* refactor: clean up HashSet import and remove call-site duplication

- Import HashSet alongside HashMap instead of using fully-qualified path
- Replace duplicated drain+apply sequence in execute_command with
  drain_cdp_events_background call

* style: apply cargo fmt

---------

Co-authored-by: hyunjinee <leehj0110@kakao.com>
This commit is contained in:
jin.2
2026-03-29 11:51:49 -06:00
committed by GitHub
co-authored by hyunjinee
parent dc26ff7667
commit 43d9c40bc4
3 changed files with 190 additions and 97 deletions
+2 -2
View File
@@ -188,8 +188,8 @@ async fn run_socket_server(
}
_ = drain_interval.tick() => {
let mut s = state.lock().await;
if s.request_tracking || s.har_recording {
s.drain_cdp_events_background();
if s.browser.is_some() {
s.drain_cdp_events_background().await;
}
}
_ = async {