pub struct NodeHandle { /* private fields */ }Expand description
more CDP Runtime.callFunctionOn calls against the held V8 remote object
reference — no HTML serialisation occurs.
A handle becomes stale after page navigation or if the underlying DOM
node is removed. Stale calls return BrowserError::StaleNode so callers
can distinguish them from other CDP failures.
§Example
use stygian_browser::{BrowserPool, BrowserConfig, WaitUntil};
use std::time::Duration;
let pool = BrowserPool::new(BrowserConfig::default()).await?;
let handle = pool.acquire().await?;
let mut page = handle.browser().expect("valid browser").new_page().await?;
page.navigate("https://example.com", WaitUntil::DomContentLoaded, Duration::from_secs(30)).await?;
let href = node.attr("href").await?;
let text = node.text_content().await?;
println!("{text}: {href:?}");Implementations§
Source§impl NodeHandle
impl NodeHandle
Sourcepub async fn attr(&self, name: &str) -> Result<Option<String>>
pub async fn attr(&self, name: &str) -> Result<Option<String>>
Return a single attribute value, or None if the attribute is absent.
Issues one Runtime.callFunctionOn CDP call (el.getAttribute(name)).
§Errors
invalidated, or BrowserError::Timeout / BrowserError::CdpError
on transport-level failures.
Sourcepub async fn attr_map(&self) -> Result<HashMap<String, String>>
pub async fn attr_map(&self) -> Result<HashMap<String, String>>
Return all attributes as a HashMap<name, value> in a single
CDP round-trip.
Uses DOM.getAttributes (via the chromiumoxide attributes() API)
which returns a flat [name, value, name, value, …] list from the node
description — no per-attribute calls are needed.
§Errors
invalidated.
Sourcepub async fn text_content(&self) -> Result<String>
pub async fn text_content(&self) -> Result<String>
Return the element’s textContent (all text inside, no markup).
Reads the DOM textContent property via a single JS eval — this is the
raw text concatenation of all descendant text nodes, independent of
layout or visibility (unlike innerText).
§Errors
invalidated.
Sourcepub async fn inner_html(&self) -> Result<String>
pub async fn inner_html(&self) -> Result<String>
Sourcepub async fn outer_html(&self) -> Result<String>
pub async fn outer_html(&self) -> Result<String>
Sourcepub async fn ancestors(&self) -> Result<Vec<String>>
pub async fn ancestors(&self) -> Result<Vec<String>>
Executes a single Runtime.callFunctionOn JavaScript function that
walks parentElement and collects tag names — no repeated CDP calls.
["p", "article", "body", "html"]§Errors
invalidated, or BrowserError::ScriptExecutionFailed when CDP
Sourcepub async fn children_matching(&self, selector: &str) -> Result<Vec<Self>>
pub async fn children_matching(&self, selector: &str) -> Result<Vec<Self>>
§Errors
invalidated, or BrowserError::CdpError on transport failure.
Sourcepub async fn parent(&self) -> Result<Option<Self>>
pub async fn parent(&self) -> Result<Option<Self>>
Return the immediate parent element, or None if this element has no
parent (i.e. it is the document root).
Issues a single Runtime.callFunctionOn CDP call that temporarily tags
the parent element with a unique attribute, then resolves it via a
CSS attribute selector.
§Errors
Returns an error if the CDP call fails or the page handle is invalidated.
§Example
use stygian_browser::{BrowserPool, BrowserConfig, WaitUntil};
use std::time::Duration;
let pool = BrowserPool::new(BrowserConfig::default()).await?;
let handle = pool.acquire().await?;
let mut page = handle.browser().expect("valid browser").new_page().await?;
page.navigate("https://example.com", WaitUntil::DomContentLoaded, Duration::from_secs(30)).await?;
if let Some(parent) = nodes[0].parent().await? {
let html = parent.outer_html().await?;
println!("parent: {}", &html[..html.len().min(80)]);
}Sourcepub async fn next_sibling(&self) -> Result<Option<Self>>
pub async fn next_sibling(&self) -> Result<Option<Self>>
Return the next element sibling, or None if this element is the last
child of its parent.
Uses nextElementSibling (skips text/comment nodes).
§Errors
invalidated.
§Example
use stygian_browser::{BrowserPool, BrowserConfig, WaitUntil};
use std::time::Duration;
let pool = BrowserPool::new(BrowserConfig::default()).await?;
let handle = pool.acquire().await?;
let mut page = handle.browser().expect("valid browser").new_page().await?;
page.navigate("https://example.com", WaitUntil::DomContentLoaded, Duration::from_secs(30)).await?;
if let Some(next) = nodes[0].next_sibling().await? {
println!("next sibling: {}", next.text_content().await?);
}Sourcepub async fn previous_sibling(&self) -> Result<Option<Self>>
pub async fn previous_sibling(&self) -> Result<Option<Self>>
Return the previous element sibling, or None if this element is the
first child of its parent.
Uses previousElementSibling (skips text/comment nodes).
§Errors
invalidated.
§Example
use stygian_browser::{BrowserPool, BrowserConfig, WaitUntil};
use std::time::Duration;
let pool = BrowserPool::new(BrowserConfig::default()).await?;
let handle = pool.acquire().await?;
let mut page = handle.browser().expect("valid browser").new_page().await?;
page.navigate("https://example.com", WaitUntil::DomContentLoaded, Duration::from_secs(30)).await?;
if let Some(prev) = nodes[1].previous_sibling().await? {
println!("prev sibling: {}", prev.text_content().await?);
}