Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust
Rust ai-agentsai-toolsbrowserbrowser-automationcloud-browserheadlessheadless-browserkitesurfplaywrightpuppeteerrustservoweb-crawlerweb-crawlingweb-scraperweb-scraping
fix(layout): honor frame scrolling policy for viewport UI and input
ldm09aee1af24e87
diff --git a/moli-layout/src/builder.rs b/moli-layout/src/builder.rsindex 2145844ef..643543498 100644--- a/moli-layout/src/builder.rs+++ b/moli-layout/src/builder.rs@@ -375,6 +375,7 @@ whereroot_style.viewport_scrollbar_gutter(),root_style.scrollbar_colors(),root_style.uses_horizontal_writing_mode(),+ self.source.disables_viewport_user_scrolling(),);}diff --git a/moli-layout/src/source.rs b/moli-layout/src/source.rsindex 53f24adb4..383c04c5d 100644--- a/moli-layout/src/source.rs+++ b/moli-layout/src/source.rs@@ -482,6 +482,13 @@ pub trait LayoutSource {fn root_is_document_element(&self) -> bool {false}+ /// Whether the embedding context disables user scrolling of this viewport,+ /// including its scrollbar UI and gutters, independently of CSS overflow.+ /// Sampled for this layout pass; descendant scroll containers and+ /// programmatic viewport scrolling keep their ordinary behavior.+ fn disables_viewport_user_scrolling(&self) -> bool {+ false+ }/// Returns the parent in the same flattened tree exposed by [`Self::flat_children`]./// The view root must return `None`, even when it has a DOM parent outside the view.fn flat_parent(&self, node: Self::NodeId) -> Option<Self::NodeId>;diff --git a/moli-layout/src/world.rs b/moli-layout/src/world.rsindex dd294f93d..ad9320bfc 100644--- a/moli-layout/src/world.rs+++ b/moli-layout/src/world.rs@@ -321,6 +321,7 @@ pub(crate) struct ViewportScrollPolicy {scrollbar_gutter: LayoutScrollbarGutter,scrollbar_colors: Option<LayoutScrollbarColors>,horizontal_writing_mode: bool,+ user_scrolling_disabled: bool,revealed_scrollbar_x: bool,revealed_scrollbar_y: bool,}@@ -334,6 +335,7 @@ impl Default for ViewportScrollPolicy {scrollbar_gutter: LayoutScrollbarGutter::Auto,scrollbar_colors: None,horizontal_writing_mode: true,+ user_scrolling_disabled: false,revealed_scrollbar_x: false,revealed_scrollbar_y: false,}@@ -348,14 +350,23 @@ impl ViewportScrollPolicy {scrollbar_gutter: LayoutScrollbarGutter,scrollbar_colors: Option<LayoutScrollbarColors>,horizontal_writing_mode: bool,+ user_scrolling_disabled: bool,) -> Self {Self {defining_box,effective_overflow,- scrollbar_width,+ // The embedder disables viewport input and scrollbar UI together.+ // Keep its restriction distinct from CSS scrollbar-width: none,+ // which only hides the scrollbar.+ scrollbar_width: if user_scrolling_disabled {+ LayoutScrollbarWidth::None+ } else {+ scrollbar_width+ },scrollbar_gutter,scrollbar_colors,horizontal_writing_mode,+ user_scrolling_disabled,revealed_scrollbar_x: false,revealed_scrollbar_y: false,}@@ -409,7 +420,7 @@ impl ViewportScrollPolicy {}pub(crate) fn allows_user_scroll(self, axis: LayoutScrollbarAxis) -> bool {- self.overflow_mode(axis).allows_user_scroll()+ !self.user_scrolling_disabled && self.overflow_mode(axis).allows_user_scroll()}pub(crate) fn clips_overflow(self) -> bool {diff --git a/moli-renderer-v8/src/layout_renderer/source_view.rs b/moli-renderer-v8/src/layout_renderer/source_view.rsindex 657278ee4..1e9a0d535 100644--- a/moli-renderer-v8/src/layout_renderer/source_view.rs+++ b/moli-renderer-v8/src/layout_renderer/source_view.rs@@ -65,6 +65,27 @@ impl LayoutSource for NativeLayoutSourceView<'_> {}) == Some(self.root)}+ fn disables_viewport_user_scrolling(&self) -> bool {+ if !self.root_is_document_element() {+ return false;+ }+ self.document+ .and_then(|document| {+ self.runtime+ .child_browsing_context_host_for_document_handle(document)+ })+ .filter(|frame| {+ self.host().is_html_element_named(*frame, "iframe")+ || self.host().is_html_element_named(*frame, "frame")+ })+ .and_then(|frame| self.host().get_attribute(frame, "scrolling"))+ .is_some_and(|value| {+ ["no", "off", "noscroll"]+ .iter()+ .any(|keyword| value.eq_ignore_ascii_case(keyword))+ })+ }+fn flat_parent(&self, node: Self::NodeId) -> Option<Self::NodeId> {native_flat_parent(self.host(), self.root, node)}diff --git a/moli-renderer-v8/src/script_vm/tests/dom_elements/dom_surface/extracted/frame_geometry_and_input.rs b/moli-renderer-v8/src/script_vm/tests/dom_elements/dom_surface/extracted/frame_geometry_and_input.rsindex a3cf201bf..139537dd8 100644--- a/moli-renderer-v8/src/script_vm/tests/dom_elements/dom_surface/extracted/frame_geometry_and_input.rs+++ b/moli-renderer-v8/src/script_vm/tests/dom_elements/dom_surface/extracted/frame_geometry_and_input.rs@@ -291,6 +291,204 @@ fn transformed_constrained_iframe_routes_hover_click_and_wheel_in_child_coordina"800|800");}+#[test]+fn iframe_scrolling_attribute_suppresses_only_viewport_scrollbars() {+ for (scrolling, suppressed) in [+ ("no", true),+ ("NO", true),+ ("off", true),+ ("NoScroll", true),+ ("auto", false),+ ("yes", false),+ (" no", false),+ ("", false),+ ] {+ for gutter in ["auto", "stable both-edges"] {+ let mut vm = new_parsed_test_vm(+ "https://iframe-scrollbar-policy.test/",+ "<!doctype html><iframe id=frame style='width:100px;height:100px;border:0'></iframe>",+ );+ vm.eval(&format!(+ r#"+ frame.scrolling = {scrolling:?};+ globalThis.child = frame.contentDocument;+ child.open();+ child.write('<!doctype html><style>html{{overflow:scroll;scrollbar-gutter:{gutter}}}body{{margin:0}}</style><div style="height:400px"><div id="scroller" style="width:70px;height:20px;overflow:scroll"><div style="height:40px"></div></div></div>');+ child.close();+ "#,+ ))+ .unwrap();+ let width = if suppressed {+ 100+ } else if gutter == "auto" {+ 85+ } else {+ 70+ };+ let query = r#"JSON.stringify([+ child.documentElement.getBoundingClientRect().width,+ child.getElementById('scroller').clientWidth,+ child.defaultView.getComputedStyle(child.documentElement).overflowY,+ child.defaultView.getComputedStyle(child.documentElement).scrollbarWidth+ ])"#;+ let expected = format!(r#"[{width},55,"scroll","auto"]"#);+ assert_eq!(+ vm.eval(query).unwrap(),+ expected,+ "{scrolling:?} / {gutter}"+ );+ publish_layout_for_test(&mut vm);+ assert_eq!(+ vm.eval(query).unwrap(),+ expected,+ "paint: {scrolling:?} / {gutter}"+ );+ assert_eq!(+ vm.eval("child.defaultView.scrollTo(0,20);child.defaultView.scrollY")+ .unwrap(),+ "20",+ "hiding scrollbar UI must preserve script scrolling"+ );+ }+ }+}++#[test]+fn iframe_scrolling_changes_apply_at_the_next_layout_publication() {+ let mut vm = new_parsed_test_vm(+ "https://iframe-scrollbar-update.test/",+ "<!doctype html><iframe id=frame scrolling=no style='width:100px;height:100px;border:0'></iframe>",+ );+ vm.eval(+ r#"+ globalThis.child = frame.contentDocument;+ child.open();+ child.write('<!doctype html><body style="margin:0"><div style="height:400px"></div>');+ child.close();+ "#,+ )+ .unwrap();+ let query = "child.documentElement.getBoundingClientRect().width";+ assert_eq!(vm.eval(query).unwrap(), "100");+ vm.eval("frame.scrolling='auto'").unwrap();+ assert_eq!(vm.eval(query).unwrap(), "100");+ publish_layout_for_test(&mut vm);+ assert_eq!(vm.eval(query).unwrap(), "85");+ vm.eval("frame.scrolling='no'").unwrap();+ assert_eq!(vm.eval(query).unwrap(), "85");+ publish_layout_for_test(&mut vm);+ assert_eq!(vm.eval(query).unwrap(), "100");+}++fn iframe_scrolling_policy_test_vm(+ scrolling: &str,+ scrollbar_width: &str,+) -> StandaloneScriptVmHarness {+ let mut vm = new_parsed_test_vm(+ "https://iframe-user-scroll-policy.test/",+ r#"<!doctype html><body style="margin:0">+ <div style="width:2400px;height:2400px"></div>+ <iframe id=frame style="position:fixed;left:0;top:0;width:240px;height:180px;border:0"></iframe>"#,+ );+ vm.eval(&format!(+ r#"+ frame.scrolling = {scrolling:?};+ globalThis.child = frame.contentWindow;+ child.document.open();+ child.document.write('<!doctype html><style>html{{overflow:scroll;scrollbar-width:{scrollbar_width}}}body{{margin:0}}</style><div style="width:1200px;height:1200px"></div><div id=scroller style="position:fixed;left:10px;top:10px;width:80px;height:60px;overflow:scroll"><div style="width:640px;height:640px"></div></div>');+ child.document.close();+ globalThis.scroller = child.document.getElementById('scroller');+ "#,+ ))+ .unwrap();+ vm+}++#[test]+fn iframe_scrolling_policy_distinguishes_wheel_input_from_scrollbar_appearance() {+ let positions = "JSON.stringify([child.scrollX,child.scrollY])";+ for (scrolling, scrollbar_width, disabled) in [+ ("auto", "none", false),+ ("auto", "auto", false),+ ("no", "auto", true),+ ("NO", "none", true),+ ("off", "auto", true),+ ("NoScroll", "auto", true),+ ] {+ for initially_published in [false, true] {+ let mut vm = iframe_scrolling_policy_test_vm(scrolling, scrollbar_width);+ if initially_published {+ publish_layout_for_test(&mut vm);+ }+ let expected = if disabled { "[0,0]" } else { "[40,120]" };+ vm.dispatch_mouse_event_at_point(150.0, 100.0, "wheel", -1, Some(0), 40.0, 120.0)+ .expect("wheel over the child viewport");+ assert_eq!(+ vm.eval(positions).unwrap(),+ expected,+ "scrolling={scrolling}, scrollbar-width={scrollbar_width}, published={initially_published}"+ );++ vm.eval("scrollTo(0,0);child.scrollTo(0,0)").unwrap();+ vm.dispatch_mouse_event_at_point(30.0, 30.0, "wheel", -1, Some(0), 40.0, 30.0)+ .expect("wheel over an ordinary descendant scroll container");+ assert_eq!(+ vm.eval("JSON.stringify([scroller.scrollLeft,scroller.scrollTop,child.scrollX,child.scrollY,scrollX,scrollY])").unwrap(),+ "[40,30,0,0,0,0]",+ "frame scrolling policy must not disable descendant containers"+ );++ vm.eval("scroller.scrollTo(10000,10000)").unwrap();+ vm.dispatch_mouse_event_at_point(30.0, 30.0, "wheel", -1, Some(0), 40.0, 120.0)+ .expect("wheel chains beyond a descendant at its scroll boundary");+ assert_eq!(+ vm.eval(positions).unwrap(),+ expected,+ "chained wheel: {scrolling}"+ );+ assert_eq!(+ vm.eval("child.scrollTo(20,20);JSON.stringify([child.scrollX,child.scrollY])")+ .unwrap(),+ "[20,20]",+ "frame scrolling policy must preserve script scrolling"+ );+ }+ }+}++#[test]+fn iframe_scrolling_policy_changes_input_permissions_at_next_publication() {+ let mut vm = iframe_scrolling_policy_test_vm("auto", "none");+ let positions = "JSON.stringify([child.scrollX,child.scrollY])";+ publish_layout_for_test(&mut vm);+ for (scrolling, publish, expected) in [+ ("no", false, "[40,120]"),+ ("no", true, "[0,0]"),+ ("auto", false, "[0,0]"),+ ("auto", true, "[40,120]"),+ ] {+ vm.eval(&format!(+ "scrollTo(0,0);child.scrollTo(0,0);frame.scrolling={scrolling:?}"+ ))+ .unwrap();+ let before = vm.layout_pass_observability_for_test().1;+ if publish {+ publish_layout_for_test(&mut vm);+ }+ vm.dispatch_mouse_event_at_point(150.0, 100.0, "wheel", -1, Some(0), 40.0, 120.0)+ .expect("wheel consumes the published viewport policy");+ assert_eq!(+ vm.eval(positions).unwrap(),+ expected,+ "{scrolling} / publish={publish}"+ );+ assert_eq!(+ vm.layout_pass_observability_for_test().1,+ before + u64::from(publish)+ );+ }+}+#[test]fn iframe_input_reuses_one_top_level_snapshot_without_parent_child_ping_pong() {let mut vm = new_storage_test_vm("https://iframe-input-snapshot.test/");