Skip to content

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

JavaScript

Count a consent root once when two selectors match it

Paul Bakaus364a61716913
diff --git a/crates/browser/src/consent.rs b/crates/browser/src/consent.rs
index 56459aab5..4a076b053 100644
--- a/crates/browser/src/consent.rs
+++ b/crates/browser/src/consent.rs
@@ -246,7 +246,9 @@ pub fn probe_fragment() -> String {
const consentRoots = [];
for (const m of consentManagers) {{
let on = false;
- for (const s of m.roots) for (const el of q(s)) if (showing(el)) {{ on = true; consentRoots.push(el); }}
+ // Two selectors can match one node (Quantcast's id and class): it is one
+ // root, counted once.
+ for (const s of m.roots) for (const el of q(s)) if (showing(el)) {{ on = true; if (!consentRoots.includes(el)) consentRoots.push(el); }}
if (on) consent.push(m.name);
}}
// A manager that renders into a shadow root (Usercentrics) keeps its text
diff --git a/crates/browser/tests/consent_hiding.rs b/crates/browser/tests/consent_hiding.rs
index 1e1c67c4c..d120fdb8b 100644
--- a/crates/browser/tests/consent_hiding.rs
+++ b/crates/browser/tests/consent_hiding.rs
@@ -351,3 +351,11 @@ fn a_late_banner_on_a_root_hidden_inline_is_reported() {
browser.close();
assert_eq!(evidence.consent.as_ref().expect("consent report").hidden, vec!["Usercentrics"]);
}
+
+#[test]
+fn a_root_matched_by_two_selectors_is_counted_once() {
+ let Some(engine) = engine() else { return };
+ let port = serve();
+ let url = format!("http://127.0.0.1:{port}/quantcast-short-page.html");
+ engine.detect_url_scan(&url, &ScanOptions::default()).expect("a short page is a page");
+}
diff --git a/tests/fixtures/consent/quantcast-short-page.html b/tests/fixtures/consent/quantcast-short-page.html
new file mode 100644
index 000000000..9513a09da
--- /dev/null
+++ b/tests/fixtures/consent/quantcast-short-page.html
@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <title>Consent hiding: one root matched by two selectors</title>
+ <style>
+ /* A short page with copy of its own under a Quantcast-shaped banner whose
+ root carries both the id and the class the manager list names. It is
+ one root and its text is counted once, so the page's copy is outside
+ it and the page is scanned. Pinned by
+ crates/browser/tests/consent_hiding.rs. */
+ body { font: 16px/1.5 system-ui, sans-serif; margin: 0; padding: 40px; color: #111; background: #fff; }
+ #qc-cmp2-container { position: fixed; left: 0; right: 0; bottom: 0; padding: 24px; background: #fff; }
+ </style>
+</head>
+<body>
+ <h1>Opening hours</h1>
+ <p>The studio is open Tuesday to Saturday from ten until six, and by appointment on Mondays and holidays.</p>
+ <div id="qc-cmp2-container" class="qc-cmp2-container">
+ <p>We and our partners store and access information on your device, such as cookies, and process personal data such as unique identifiers and browsing data, to personalise content and advertising and to measure its performance.</p>
+ </div>
+</body>
+</html>