Files
pbakaus_impeccable/crates/browser/tests/isolated_world.rs
T
Paul Bakaus 6a93a35293 Add human component review and prepare Impeccable 4.4.0
Carry native comp capture and completion integrity fixes into the reviewed component workflow. Bump the skill to 4.4.0 and engine/platform pins to 0.1.6; keep publication separate from this release candidate.

AI assistance: implemented and validated with OpenAI Codex.
2026-09-13 20:41:09 -07:00

50 lines
1.9 KiB
Rust

use impeccable_browser::{cdp::Browser, discovery};
use std::time::Duration;
#[test]
fn isolated_world_keeps_page_prototypes_and_globals_separate_and_rejects_navigation() {
let env = std::env::vars().collect();
let Ok(exe) = discovery::find_browser(&env) else {
eprintln!("skip: no browser");
return;
};
let mut browser = Browser::launch(&exe, &[], false).unwrap();
let mut page = browser.new_page().unwrap();
page.goto("data:text/html,<div id='target' style='position:absolute;left:20px;top:20px;width:80px;height:80px'></div>","load",Duration::from_secs(15)).unwrap();
page.evaluate_value(
"Element.prototype.getBoundingClientRect=function(){return new DOMRect(999,999,1,1)};true",
)
.unwrap();
let world = page.create_isolated_world().unwrap();
assert_eq!(
page.evaluate_value("document.querySelector('#target').getBoundingClientRect().x")
.unwrap(),
999
);
assert_eq!(
page.evaluate_value_in_world(
&world,
"document.querySelector('#target').getBoundingClientRect().x"
)
.unwrap(),
20
);
page.evaluate_value_in_world(&world, "globalThis.__capture_secret=42;true")
.unwrap();
assert_eq!(
page.evaluate_value("typeof globalThis.__capture_secret")
.unwrap(),
"undefined"
);
page.goto("about:blank", "load", Duration::from_secs(15))
.unwrap();
assert!(
page.evaluate_value_in_world(&world, "true").is_err(),
"old world must not follow navigation"
);
let next = page.create_isolated_world().unwrap();
assert!(page.evaluate_value_in_world(&next,"setTimeout(()=>location.href='about:blank',0);new Promise(r=>setTimeout(()=>r(true),100))").is_err(),"navigation while awaiting must not return successful evidence");
page.close();
browser.close();
}