The headless browser for AI agents and web scraping
Merge branch 'maintainer/pr-508-review' into maintainer/pr-510-review
SGavrlb5c2f9cc4ea2
diff --cc crates/obscura-js/src/runtime.rsindex 4c8a16ec,3eb51b60..dc7bc7fb--- a/crates/obscura-js/src/runtime.rs+++ b/crates/obscura-js/src/runtime.rs@@@ -1317,26 -1317,28 +1317,48 @@@ mod testsrt}+ #[test]+ fn childnode_helpers_coerce_non_string_primitives_to_text() {+ let mut rt = setup_runtime(r#"<html><body><div id="p"><span id="t">x</span></div></body></html>"#);+ let before = rt+ .evaluate("(function(){var t=document.getElementById('t'); t.before(5); return t.previousSibling ? t.previousSibling.textContent : 'NULL';})()")+ .unwrap();+ assert_eq!(before, serde_json::json!("5"));+ let after = rt+ .evaluate("(function(){var t=document.getElementById('t'); t.after(true); return t.nextSibling ? t.nextSibling.textContent : 'NULL';})()")+ .unwrap();+ assert_eq!(after, serde_json::json!("true"));+ let replaced = rt+ .evaluate("(function(){var t=document.getElementById('t'); t.replaceWith(42); return document.getElementById('p').textContent;})()")+ .unwrap();+ assert!(+ replaced.as_str().unwrap().contains("42"),+ "replaceWith(42) should leave text '42': {replaced}"+ );+ }++ #[test]+ fn replace_state_without_url_preserves_current_location() {+ let mut rt = setup_runtime("<html><body></body></html>");+ let path = rt+ .evaluate(+ "(function(){history.pushState({}, '', '/dashboard'); history.replaceState({scroll:1}); return location.pathname;})()",+ )+ .unwrap();+ assert_eq!(path, serde_json::json!("/dashboard"));+ }++ #[test]+ fn push_state_without_url_preserves_current_location() {+ let mut rt = setup_runtime("<html><body></body></html>");+ let path = rt+ .evaluate(+ "(function(){history.pushState({}, '', '/a'); history.pushState({b:1}); return location.pathname;})()",+ )+ .unwrap();+ assert_eq!(path, serde_json::json!("/a"));+ }+#[test]fn test_document_title() {let mut rt = setup_runtime("<html><head><title>Test</title></head><body></body></html>");