From f71d9124e7e3a0ef3cbe55dcbdeba75bc4d5cd33 Mon Sep 17 00:00:00 2001 From: Andrei Iatsuk <5247416+iatsuk@users.noreply.github.com> Date: Tue, 17 Nov 2026 07:30:56 +0100 Subject: [PATCH] feat(fetch): show link URLs in the semantic tree text dump --- moli/src/fetch_dump/semantic.rs | 33 +++++++++++++++++++ moli/src/fetch_dump/tests.rs | 3 ++ .../moli-webfetch/references/fetch-recipes.md | 2 +- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/moli/src/fetch_dump/semantic.rs b/moli/src/fetch_dump/semantic.rs index 4994e5cb906..837f14c91fd 100644 --- a/moli/src/fetch_dump/semantic.rs +++ b/moli/src/fetch_dump/semantic.rs @@ -101,6 +101,18 @@ fn render_payloads_text(payloads: &[AccessibilityNode]) -> String { out.push_str(" = "); out.push_str(value); } + if node.role == "link" + && let Some(url) = node + .properties() + .into_iter() + .flatten() + .find(|property| property["name"] == "url") + .and_then(|property| property["value"]["value"].as_str()) + && !url.is_empty() + { + out.push_str(" → "); + out.push_str(url); + } if let Some(backend) = node.backend_node_id { write!(&mut out, " [backendNodeId={backend}]").expect("writing to a String"); } @@ -223,4 +235,25 @@ mod tests { assert_eq!(text.lines().count(), (DEPTH + 1) as usize); assert!(text.ends_with(" - textbox: Name = value [backendNodeId=2049]")); } + + #[test] + fn text_shows_the_url_of_links_only() { + let url = || { + Some(vec![ + serde_json::json!({"name":"url", "value":{"type":"string", "value":"https://example.com/a"}}), + ]) + }; + let mut link = node(2, "link", Some(1), &[]); + link.name = Some("A".to_owned()); + link.set_rare_data(None, None, url()); + let mut image = node(3, "image", Some(1), &[]); + image.set_rare_data(None, None, url()); + let text = render_payloads_text(&[node(1, "RootWebArea", None, &[2, 3]), link, image]); + assert_eq!( + text, + "- RootWebArea [backendNodeId=1]\n \ + - link: A → https://example.com/a [backendNodeId=2]\n \ + - image [backendNodeId=3]" + ); + } } diff --git a/moli/src/fetch_dump/tests.rs b/moli/src/fetch_dump/tests.rs index a41c634dd4e..9bbe95e8872 100644 --- a/moli/src/fetch_dump/tests.rs +++ b/moli/src/fetch_dump/tests.rs @@ -289,6 +289,7 @@ async fn semantic_dump_preserves_protocol_json_bytes_and_text_fields() -> Result + Docs "#, @@ -338,6 +339,8 @@ async fn semantic_dump_preserves_protocol_json_bytes_and_text_fields() -> Result let text = super::semantic::render_text(&mut page, false).await?; assert!(text.contains("textbox: Text field = field value [backendNodeId=")); assert!(text.contains("textbox: Numeric field = 42 [backendNodeId=")); + let link_url = page.final_url().join("docs/start.html#top")?; + assert!(text.contains(&format!("link: Docs → {link_url} [backendNodeId="))); assert!( !text.contains("ListMarker"), "markers have no child reference in the protocol tree" diff --git a/skills/moli-webfetch/references/fetch-recipes.md b/skills/moli-webfetch/references/fetch-recipes.md index f0dfdbe16c1..b9e4c89c5c5 100644 --- a/skills/moli-webfetch/references/fetch-recipes.md +++ b/skills/moli-webfetch/references/fetch-recipes.md @@ -16,7 +16,7 @@ | Need | Command shape | Notes | | --- | --- | --- | | Read page content | `--dump markdown` | Default for research and summarization | -| Inspect semantic structure | `--dump semantic_tree_text` | Compact roles, labels, text, and backend node IDs | +| Inspect semantic structure | `--dump semantic_tree_text` | Compact roles, labels, text, link URLs, and backend node IDs | | Process semantic structure | `--dump semantic_tree` | Structured accessibility-oriented payload | | Process stable fields | `--dump json` | Returns response metadata plus rendered `html` or a raw `body_base64` | | Inspect exact DOM | `--dump html` | Useful when Markdown loses important structure |