Skip to content

The design language that makes your AI harness better at design.

JavaScript

Count consent text under a display: contents wrapper in a manager's shadow root

Paul Bakaus40f5267db672
diff --git a/crates/browser/src/consent.rs b/crates/browser/src/consent.rs
index 2abb57560..24f32a28b 100644
--- a/crates/browser/src/consent.rs
+++ b/crates/browser/src/consent.rs
@@ -266,10 +266,19 @@ pub fn probe_fragment() -> String {
const root = host.shadowRoot;
if (!root) continue;
// innerText of an unrendered child (a <style>) is its source text.
- for (const child of root.children) if (boxShows(child)) text += visibleText(child);
+ for (const child of root.children) text += shadowText(child);
}}
return text;
}};
+ // A `display: contents` wrapper has no box of its own; its children do.
+ const shadowText = el => {{
+ if (boxShows(el)) return visibleText(el);
+ let n = 0;
+ try {{
+ if (getComputedStyle(el).display === 'contents') for (const k of el.children) n += shadowText(k);
+ }} catch (e) {{}}
+ return n;
+ }};
// `consentShadowChars` is the part of that text the page's own
// `body.innerText` cannot see, so the probe adds it to the page's count and
// the two counts describe the same text. `consentFrames` counts sizable
@@ -307,15 +316,6 @@ pub fn probe_fragment() -> String {
// shadow roots (a web-component app), which `body.innerText` does not see
// either: it counts as text outside the managers.
let consentPageShadowChars = 0;
- // A `display: contents` wrapper has no box of its own; its children do.
- const shadowText = el => {{
- if (boxShows(el)) return visibleText(el);
- let n = 0;
- try {{
- if (getComputedStyle(el).display === 'contents') for (const k of el.children) n += shadowText(k);
- }} catch (e) {{}}
- return n;
- }};
// The page's open shadow roots, outside the managers: their form
// controls and media are the page's as much as their text is.
const pageShadows = [];
diff --git a/crates/browser/tests/consent_hiding.rs b/crates/browser/tests/consent_hiding.rs
index 9fb51e4db..04c9a24b5 100644
--- a/crates/browser/tests/consent_hiding.rs
+++ b/crates/browser/tests/consent_hiding.rs
@@ -270,6 +270,17 @@ fn a_wall_rendered_in_a_shadow_root_is_refused() {
assert!(err.message.starts_with("the page is a consent wall, not the site (consent manager Usercentrics, "), "{}", err.message);
}
+#[test]
+fn a_wall_under_a_contents_wrapper_in_a_shadow_root_is_refused() {
+ let Some(engine) = engine() else { return };
+ let port = serve();
+ let url = format!("http://127.0.0.1:{port}/shadow-contents-wall.html");
+ let err = engine
+ .detect_url(&url, &ScanOptions::default())
+ .expect_err("a consent wall under a display: contents wrapper must not scan");
+ assert!(err.message.starts_with("the page is a consent wall, not the site (consent manager Usercentrics, "), "{}", err.message);
+}
+
#[test]
fn a_lock_the_sites_own_modal_holds_stays() {
let Some(engine) = engine() else { return };
diff --git a/tests/fixtures/consent/shadow-contents-wall.html b/tests/fixtures/consent/shadow-contents-wall.html
new file mode 100644
index 000000000..982a48475
--- /dev/null
+++ b/tests/fixtures/consent/shadow-contents-wall.html
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <title>Consent hiding: a shadow-root consent wall under a display: contents wrapper</title>
+ <style>
+ /* shadow-wall.html with the dialog under a `display: contents` wrapper
+ in the shadow root: the wrapper has no box of its own, and the text
+ under it still counts toward the wall.
+ Pinned by crates/browser/tests/consent_hiding.rs. */
+ body { font: 16px/1.5 system-ui, sans-serif; margin: 0; background: #f3f4f6; }
+ </style>
+</head>
+<body>
+ <div id="usercentrics-root"></div>
+ <script>
+ document.getElementById('usercentrics-root').attachShadow({ mode: 'open' }).innerHTML =
+ '<style>.box { position: fixed; top: 80px; left: 50%; width: 640px; margin-left: -320px; padding: 32px; background: #fff; }</style>'
+ + '<div style="display: contents"><div class="box" role="dialog" aria-label="Privacy settings"><h2>Privacy settings</h2>'
+ + '<p>We use cookies and similar technologies to provide this website, to measure how it is used and to show you personalised content and advertising. You can accept all of these purposes, reject them, or choose which ones you allow in the settings.</p>'
+ + '<button type="button">Accept all</button> <button type="button">Deny</button></div></div>';
+ </script>
+</body>
+</html>