Skip to content

The headless browser for AI agents and web scraping

js: expose five missing longhands and the cssFloat alias to getComputedStyle

Alex Skinnerc280615ae734
diff --git a/crates/obscura-js/js/bootstrap.js b/crates/obscura-js/js/bootstrap.js
index 9d45822f..ff04e88a 100644
--- a/crates/obscura-js/js/bootstrap.js
+++ b/crates/obscura-js/js/bootstrap.js
@@ -9801,6 +9801,10 @@ globalThis.getComputedStyle = (el, pseudo = '') => {
// (`-webkit-line-clamp`). Normalize the prefix once for every WebKit
// property instead of adding per-property aliases to the native snapshot.
if (kebab.startsWith('webkit-')) kebab = '-' + kebab;
+ // `cssFloat` is the CSSOM IDL alias for `float` (`float` being reserved in
+ // early ECMAScript). Naive camelCase splitting yields `css-float`, which
+ // matches no property, so the getter returned ''.
+ if (kebab === 'css-float') kebab = 'float';
refreshRendered(kebab);
if (snapshot.rendered && Object.prototype.hasOwnProperty.call(snapshot.rendered, kebab))
return snapshot.rendered[kebab];
diff --git a/crates/obscura-render/src/paint.rs b/crates/obscura-render/src/paint.rs
index 5be283aa..4d09477c 100644
--- a/crates/obscura-render/src/paint.rs
+++ b/crates/obscura-render/src/paint.rs
@@ -1725,6 +1725,58 @@ impl PreparedRender {
let style = self.layout.styles.get(&id)?;
let rect = self.layout.rects.get(&id);
let mut out = non_geometric_computed_style(style);
+ out.insert(
+ "vertical-align",
+ match style.vertical_align {
+ Some(crate::VerticalAlign::Top) => "top",
+ Some(crate::VerticalAlign::Middle) => "middle",
+ Some(crate::VerticalAlign::Bottom) => "bottom",
+ None => "baseline",
+ }
+ .to_string(),
+ );
+ out.insert(
+ "text-transform",
+ match style.text_transform {
+ Some(crate::TextTransform::Uppercase) => "uppercase",
+ Some(crate::TextTransform::Lowercase) => "lowercase",
+ Some(crate::TextTransform::Capitalize) => "capitalize",
+ Some(crate::TextTransform::None) | None => "none",
+ }
+ .to_string(),
+ );
+ out.insert(
+ "list-style-type",
+ match style.list_style {
+ Some(crate::ListStyle::Disc) => "disc",
+ Some(crate::ListStyle::Circle) => "circle",
+ Some(crate::ListStyle::Square) => "square",
+ Some(crate::ListStyle::Decimal) => "decimal",
+ Some(crate::ListStyle::None) => "none",
+ // The initial value is `disc`; the UA sheet only sets a marker
+ // on list items, so an unstyled element still reports it.
+ None => "disc",
+ }
+ .to_string(),
+ );
+ out.insert(
+ "border-collapse",
+ if style.border_collapse == Some(true) {
+ "collapse"
+ } else {
+ "separate"
+ }
+ .to_string(),
+ );
+ out.insert(
+ "table-layout",
+ if style.table_layout_fixed {
+ "fixed"
+ } else {
+ "auto"
+ }
+ .to_string(),
+ );
out.insert("font-size", css_px(style.font_size.unwrap_or(16.0)));
out.insert(
"font-weight",
@@ -17352,6 +17404,43 @@ mod tests {
assert_eq!(computed("plain")["clear"], "none");
}
+ /// `vertical-align`, `text-transform`, `list-style-type`, `border-collapse`
+ /// and `table-layout` are cascaded and used by layout, but were never put
+ /// in the computed-style snapshot, so `getComputedStyle()` returned `''`
+ /// for them even when the page declared them explicitly. Chromium 147
+ /// values are asserted for both the declared and the initial case.
+ #[test]
+ fn computed_style_exposes_table_list_and_text_longhands() {
+ let tree = parse_html(
+ r#"<style>#set{vertical-align:middle;list-style-type:square;
+ border-collapse:collapse;table-layout:fixed;text-transform:uppercase}</style>
+ <table id="set"><tr><td>x</td></tr></table>
+ <div id="unset">a</div>"#,
+ );
+ let mut resources = RenderResourceCache::default();
+ let prepared =
+ prepare_dom(&tree, (320.0, 200.0), None, &mut resources).expect("prepared render");
+ let computed = |id| {
+ prepared
+ .computed_style(tree.get_element_by_id(id).unwrap())
+ .expect("computed style")
+ };
+
+ let set = computed("set");
+ assert_eq!(set["vertical-align"], "middle");
+ assert_eq!(set["list-style-type"], "square");
+ assert_eq!(set["border-collapse"], "collapse");
+ assert_eq!(set["table-layout"], "fixed");
+ assert_eq!(set["text-transform"], "uppercase");
+
+ let unset = computed("unset");
+ assert_eq!(unset["vertical-align"], "baseline");
+ assert_eq!(unset["list-style-type"], "disc");
+ assert_eq!(unset["border-collapse"], "separate");
+ assert_eq!(unset["table-layout"], "auto");
+ assert_eq!(unset["text-transform"], "none");
+ }
+
#[test]
fn paints_inline_svg_with_framework_colon_attribute() {
let tree = obscura_dom::parse_html(