feat(fetch): show link URLs in the semantic tree text dump

This commit is contained in:
Andrei Iatsuk
2026-11-17 07:30:56 +01:00
parent d081ee3357
commit f71d9124e7
3 changed files with 37 additions and 1 deletions
+33
View File
@@ -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]"
);
}
}
+3
View File
@@ -289,6 +289,7 @@ async fn semantic_dump_preserves_protocol_json_bytes_and_text_fields() -> Result
<input aria-label="Text field" value="field value">
<input type="range" aria-label="Numeric field" value="42">
<button disabled>Disabled action</button>
<a href="docs/start.html#top">Docs</a>
<div aria-hidden="true"><span>Ignored text</span></div>
<div hidden>Not rendered</div>
</body></html>"#,
@@ -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"
@@ -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 |