Skip to content

The headless browser for AI agents and web scraping

Merge pull request #590 from mnaza/fix/obscura-escape-attribute-name-583

SGavrl8ceac6200025
diff --cc crates/obscura/src/page.rs
index ad02b517,9ae81216..a0b81feb
--- a/crates/obscura/src/page.rs
+++ b/crates/obscura/src/page.rs
@@@ -35,23 -43,15 +43,26 @@@ impl Page
}
/// Execute JS in the page.
- pub fn evaluate(&mut self, expression: &str) -> Value {
- self.inner.evaluate(expression)
+ ///
+ /// Takes `&self` via interior mutability so element handles that borrow the
+ /// page immutably can drive evaluation without any `unsafe` aliasing.
+ pub fn evaluate(&self, expression: &str) -> Value {
+ self.inner.borrow_mut().evaluate(expression)
}
+ /// URLs of the page's child frames, in creation order.
+ pub fn frame_urls(&self) -> Vec<String> {
+ self.inner.frame_urls()
+ }
+
+ /// Execute JS inside one of the page's child frames. Each frame is its own
+ /// realm with its own document, so this is the only way to observe one.
+ pub fn evaluate_in_frame(&mut self, index: usize, expression: &str) -> Result<Value, String> {
+ self.inner.evaluate_in_frame(index, expression)
+ }
+
/// Get page HTML content.
- pub fn content(&mut self) -> String {
+ pub fn content(&self) -> String {
let val = self.evaluate("document.documentElement.outerHTML");
val.as_str().unwrap_or("").to_string()
}