Skip to content

Commit 8348b77

Browse files
authored
fix: filter chrome:// internal targets from auto-connect discovery (#827)
When using --auto-connect, discover_and_attach_targets() was selecting Chrome internal pages (chrome://, chrome-extension://, devtools://) as the active target. Follow-up commands like `get url` and `snapshot` would then return data from targets like chrome://omnibox-popup.top-chrome/ instead of the actual application tab. Add is_internal_chrome_target() filter to exclude internal Chrome targets from the discovery results. If no user-facing targets remain after filtering, the existing "create a new tab" fallback handles it. Fixes #813 Co-authored-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
1 parent 609f32c commit 8348b77

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

cli/src/native/browser.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ fn validate_lightpanda_options(options: &LaunchOptions) -> Result<(), String> {
8787
Ok(())
8888
}
8989

90+
/// Returns true for Chrome internal targets that should not be selected
91+
/// during auto-connect (e.g. chrome://, chrome-extension://, devtools://).
92+
fn is_internal_chrome_target(url: &str) -> bool {
93+
url.starts_with("chrome://")
94+
|| url.starts_with("chrome-extension://")
95+
|| url.starts_with("devtools://")
96+
}
97+
9098
/// Converts common error messages into AI-friendly, actionable descriptions.
9199
pub fn to_ai_friendly_error(error: &str) -> String {
92100
let lower = error.to_lowercase();
@@ -327,7 +335,9 @@ impl BrowserManager {
327335
.target_infos
328336
.into_iter()
329337
.filter(|t| {
330-
(t.target_type == "page" || t.target_type == "webview") && !t.url.is_empty()
338+
(t.target_type == "page" || t.target_type == "webview")
339+
&& !t.url.is_empty()
340+
&& !is_internal_chrome_target(&t.url)
331341
})
332342
.collect();
333343

@@ -1442,4 +1452,21 @@ mod tests {
14421452
));
14431453
assert!(err.contains("Target.setDiscoverTargets failed"));
14441454
}
1455+
1456+
#[test]
1457+
fn test_is_internal_chrome_target() {
1458+
assert!(is_internal_chrome_target("chrome://newtab/"));
1459+
assert!(is_internal_chrome_target(
1460+
"chrome://omnibox-popup.top-chrome/"
1461+
));
1462+
assert!(is_internal_chrome_target(
1463+
"chrome-extension://abc123/popup.html"
1464+
));
1465+
assert!(is_internal_chrome_target(
1466+
"devtools://devtools/bundled/inspector.html"
1467+
));
1468+
assert!(!is_internal_chrome_target("https://example.com"));
1469+
assert!(!is_internal_chrome_target("http://localhost:3000"));
1470+
assert!(!is_internal_chrome_target("about:blank"));
1471+
}
14451472
}

0 commit comments

Comments
 (0)