Skip to content

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

JavaScript

Consent walls look through display: contents in the page's shadow roots

Paul Bakausb150d531a529
diff --git a/crates/browser/src/consent.rs b/crates/browser/src/consent.rs
index 87ee1657e..c316e631d 100644
--- a/crates/browser/src/consent.rs
+++ b/crates/browser/src/consent.rs
@@ -301,12 +301,21 @@ 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;
+ }};
if (consentRoots.length && document.body) {{
const hosts = document.body.querySelectorAll('*');
for (let i = 0; i < hosts.length && i < 30000; i++) {{
const host = hosts[i];
if (!host.shadowRoot || consentRoots.some(r => r.contains(host))) continue;
- for (const child of host.shadowRoot.children) if (boxShows(child)) consentPageShadowChars += visibleText(child);
+ for (const child of host.shadowRoot.children) consentPageShadowChars += shadowText(child);
}}
}}
if (consentRoots.length) {{
diff --git a/tests/fixtures/consent/shadow-app-page.html b/tests/fixtures/consent/shadow-app-page.html
index b5b7c908d..24c22ee26 100644
--- a/tests/fixtures/consent/shadow-app-page.html
+++ b/tests/fixtures/consent/shadow-app-page.html
@@ -8,7 +8,8 @@
/* A page whose own text lives in an open shadow root, under a
light-DOM OneTrust dialog that holds all of body.innerText. The
shadow text is the page's, so it is scanned, not refused as a consent
- wall. Pinned by crates/browser/tests/consent_hiding.rs. */
+ wall, and the root's display: contents wrapper is looked through.
+ Pinned by crates/browser/tests/consent_hiding.rs. */
body { font: 16px/1.5 system-ui, sans-serif; margin: 0; background: #fff; }
#onetrust-pc-sdk { position: fixed; top: 80px; left: 50%; width: 640px; margin-left: -320px; padding: 32px; background: #fff; }
</style>
@@ -23,7 +24,7 @@
</div>
<script>
const root = document.querySelector('x-app').attachShadow({ mode: 'open' });
- root.innerHTML = '<main style="display:block;padding:24px"><h1>Field notes</h1><p>The ferry leaves the harbour at seven, crosses the strait in a little under two hours and reaches the island before the morning market closes. Most visitors walk from the pier to the old town, stop at the bakery by the church and take the coast path north towards the lighthouse.</p></main>';
+ root.innerHTML = '<div style="display:contents"><main style="display:block;padding:24px"><h1>Field notes</h1><p>The ferry leaves the harbour at seven, crosses the strait in a little under two hours and reaches the island before the morning market closes. Most visitors walk from the pier to the old town, stop at the bakery by the church and take the coast path north towards the lighthouse.</p></main></div>';
</script>
</body>
</html>