Skip to content

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

JavaScript

URL capture follow-ups: RTL pixel clips, shell footers, consent races, repeated ids (#967)

Paul Bakaus69904a9a8d87
diff --git a/crates/browser/src/consent.rs b/crates/browser/src/consent.rs
index ee7a25d89..f49096545 100644
--- a/crates/browser/src/consent.rs
+++ b/crates/browser/src/consent.rs
@@ -229,6 +229,17 @@ pub const CONSENT_MANAGERS: &[ConsentManager] = &[
/// The id of the style element the hide step injects.
pub const HIDE_STYLE_ID: &str = "impeccable-consent-hide";
+
+/// Page JS: `el => bool`, whether an element marked with
+/// [`INLINE_HIDE_MARK`] still carries the inline hide a pass stamped on it,
+/// so lifting it shows the element as its manager left it. A manager that
+/// has since set its own display keeps what it set: a different value or
+/// priority, or the same `none !important` written by rewriting its style
+/// attribute (closing its dialog), which leaves the attribute's text apart
+/// from the declarations the stamp serialized. A rewrite that spells the
+/// stamp's own serialization, or a `setProperty` of the same value, changes
+/// nothing the page can observe.
+pub const STAMP_IS_OURS_JS: &str = "(el => el.style.getPropertyValue('display') === 'none' && el.style.getPropertyPriority('display') === 'important' && el.getAttribute('style') === el.style.cssText)";
/// The attribute the hide step puts on an element it hid with an inline
/// `display: none !important` (a manager whose own inline `!important`
/// outranks the rule), holding the inline `display` it replaced as
@@ -256,12 +267,72 @@ fn managers_json() -> Value {
/// Page JS shared by the probe and the hide step. `showing(el)` is whether an
/// element (or, for a zero-size wrapper such as `#onetrust-consent-sdk`, one
/// of its first descendants) paints a visible box.
+///
+/// A box with a size can still be out of every visitor's sight: a closed
+/// dialog a fixed layer parks past the viewport's edge, a box wholly above
+/// or beside the document, or one an ancestor's overflow clips away (a bar
+/// inside a wrapper collapsed to no height). `parkedAway` rejects those, as
+/// the rule pass's painted predicate does (`OutsideDocument`, `ClippedOut`).
+/// An overflow clip counts only on the ancestors that clip the box: an
+/// absolutely positioned box escapes the static ones between it and its
+/// containing block, and a fixed box every one below the ancestor that holds
+/// it (a transform, a filter, containment), or all of them when none does.
const SHOWING_JS: &str = r#"const q = s => { try { return Array.from(document.querySelectorAll(s)); } catch (e) { return []; } };
+ const flatUp = n => n.assignedSlot || n.parentElement || (n.parentNode && n.parentNode.host) || null;
+ // Whether a box makes a fixed descendant scroll with it (a transform, a
+ // filter, layout or paint containment), as the full-page screenshot asks.
+ const holdsFixed = cs => {
+ const none = v => !v || v === 'none';
+ return !none(cs.transform) || !none(cs.translate) || !none(cs.scale) || !none(cs.rotate)
+ || !none(cs.filter) || !none(cs.backdropFilter) || !none(cs.perspective)
+ || /transform|translate|scale|rotate|filter|perspective/.test(cs.willChange || '')
+ || /paint|layout|strict|content/.test(cs.contain || '');
+ };
+ const parkedAway = (el, r) => {
+ const vw = window.innerWidth || 0, vh = window.innerHeight || 0;
+ const de = document.documentElement;
+ const top = a => !a || a === de || a === document.body;
+ // Up the chain of boxes that hold the box, each one's clip asked: an
+ // in-flow box's parent, an absolutely positioned box's nearest
+ // positioned (or fixed-holding) ancestor, a fixed box's nearest
+ // fixed-holding ancestor, or the viewport when it has none.
+ let pos = getComputedStyle(el).position;
+ let cur = el;
+ let viewport = false;
+ for (let n = 0; n < 60; n++) {
+ let a = flatUp(cur);
+ let cs = null;
+ for (; !top(a) && n < 60; a = flatUp(a), n++) {
+ cs = getComputedStyle(a);
+ if (cs.display === 'contents') continue;
+ if (pos === 'fixed' ? holdsFixed(cs) : pos === 'absolute' ? (cs.position !== 'static' || holdsFixed(cs)) : true) break;
+ }
+ if (top(a)) {
+ viewport = pos === 'fixed' && !(document.body && holdsFixed(getComputedStyle(document.body))) && !holdsFixed(getComputedStyle(de));
+ break;
+ }
+ const clipX = cs.overflowX !== 'visible', clipY = cs.overflowY !== 'visible';
+ if (clipX || clipY) {
+ const pr = a.getBoundingClientRect();
+ if ((clipX && (r.right <= pr.left || r.left >= pr.right)) || (clipY && (r.bottom <= pr.top || r.top >= pr.bottom))) return true;
+ }
+ cur = a;
+ pos = cs.position;
+ }
+ if (viewport) return vw > 0 && vh > 0 && (r.right <= 0 || r.bottom <= 0 || r.left >= vw || r.top >= vh);
+ if (r.bottom + window.scrollY <= 0) return true;
+ const se = document.scrollingElement || de;
+ const docW = se ? se.scrollWidth : 0;
+ if (!(docW > 0) || !(vw > 0)) return false;
+ const rtl = getComputedStyle(de).direction === 'rtl';
+ const start = rtl ? vw - docW : 0, end = rtl ? vw : docW;
+ return r.right + window.scrollX <= start || r.left + window.scrollX >= end;
+ };
const boxShows = el => {
try {
if (el.checkVisibility && !el.checkVisibility({ opacityProperty: true, visibilityProperty: true })) return false;
const r = el.getBoundingClientRect();
- return r.width >= 1 && r.height >= 1;
+ return r.width >= 1 && r.height >= 1 && !parkedAway(el, r);
} catch (e) { return false; }
};
const showing = el => {
@@ -364,16 +435,24 @@ pub fn probe_fragment() -> String {
// either: it counts as text outside the managers.
let consentPageShadowChars = 0;
// The page's open shadow roots, outside the managers: their form
- // controls and media are the page's as much as their text is.
+ // controls and media are the page's as much as their text is. Roots
+ // nested inside other roots (a login component in an app shell's tree)
+ // count too; their text is already in the outer root's, so only the roots
+ // on light-DOM hosts add text.
const pageShadows = [];
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;
- pageShadows.push(host.shadowRoot);
- for (const child of host.shadowRoot.children) consentPageShadowChars += shadowText(child);
- }}
+ let seen = 0;
+ const visitShadows = (scope, top) => {{
+ const hosts = scope.querySelectorAll('*');
+ for (let i = 0; i < hosts.length && seen < 30000; i++, seen++) {{
+ const host = hosts[i];
+ if (!host.shadowRoot || consentRoots.some(r => r.contains(host))) continue;
+ pageShadows.push(host.shadowRoot);
+ if (top) for (const child of host.shadowRoot.children) consentPageShadowChars += shadowText(child);
+ visitShadows(host.shadowRoot, false);
+ }}
+ }};
+ visitShadows(document.body, true);
}}
if (consentRoots.length) {{
const inside = el => consentRoots.some(r => r.contains(el));
@@ -437,7 +516,7 @@ pub fn hide_js() -> String {
if (style) style.disabled = true;
// So are the inline hides an earlier pass stamped, while they are still
// its own (a manager that has since set its own display keeps it).
- const lifted = q('[' + INLINE_MARK + ']').filter(el => el.style.getPropertyValue('display') === 'none' && el.style.getPropertyPriority('display') === 'important');
+ const lifted = q('[' + INLINE_MARK + ']').filter({stamp_is_ours});
for (const el of lifted) {{
let prev = ['', ''];
try {{ prev = JSON.parse(el.getAttribute(INLINE_MARK)); }} catch (e) {{}}
@@ -533,6 +612,7 @@ pub fn hide_js() -> String {
style_id = json!(HIDE_STYLE_ID),
inline_mark = json!(INLINE_HIDE_MARK),
showing = SHOWING_JS,
+ stamp_is_ours = STAMP_IS_OURS_JS,
)
}
diff --git a/crates/browser/src/fullpage.rs b/crates/browser/src/fullpage.rs
index 85ca0ad18..f85ee24bd 100644
--- a/crates/browser/src/fullpage.rs
+++ b/crates/browser/src/fullpage.rs
@@ -75,10 +75,13 @@ pub struct Scroller {
impl Scroller {
/// The page's height with this scroller unrolled: its content from where
- /// the rects were measured, plus whatever sits below its box.
- pub fn unrolled_height(&self, viewport_height: f64) -> f64 {
+ /// the rects were measured, plus whatever sits below its box, to the
+ /// viewport's foot or, when the document scrolls a little further (a
+ /// footer under a 100vh shell), to the document's.
+ pub fn unrolled_height(&self, viewport_height: f64, document_height: f64) -> f64 {
let box_bottom = self.top + self.client_height;
- self.top + self.scroll_height - self.scroll_top + (viewport_height - box_bottom).max(0.0)
+ let foot = viewport_height.max(document_height);
+ self.top + self.scroll_height - self.scroll_top + (foot - box_bottom).max(0.0)
}
/// The viewport rows it shows, `[top, bottom)`.
@@ -229,11 +232,11 @@ const GEOMETRY_JS: &str = r#"(() => {
return out;
})()"#;
-const SCROLL_TO_JS: &str = r#"(async ({ x, y, useScroller, hideFixed }) => {
+const SCROLL_TO_JS: &str = r#"(async ({ x, y, useScroller, hideFixed, docY }) => {
const el = useScroller ? window.__impeccableShotScroller : null;
if (useScroller && !el) throw new Error('the page scroller is gone');
if (el) {
- window.scrollTo({ left: x, top: 0, behavior: 'instant' });
+ window.scrollTo({ left: x, top: docY || 0, behavior: 'instant' });
el.scrollTo({ left: el.scrollLeft, top: y, behavior: 'instant' });
} else {
window.scrollTo({ left: x, top: y, behavior: 'instant' });
@@ -244,6 +247,7 @@ const SCROLL_TO_JS: &str = r#"(async ({ x, y, useScroller, hideFixed }) => {
const pos = {
x: window.scrollX,
y: el ? el.scrollTop : window.scrollY,
+ docY: window.scrollY,
maxY: el ? el.scrollHeight - el.clientHeight : se.scrollHeight - window.innerHeight,
};
// Every element under body, open shadow trees included: chrome a widget
@@ -424,7 +428,7 @@ fn capture_with(
if let Some(scroller) = geometry.scroller {
let document_height = geometry
.document_height
- .max(scroller.unrolled_height(geometry.viewport_height))
+ .max(scroller.unrolled_height(geometry.viewport_height, geometry.document_height))
.round();
let height = document_height.min(max_height).max(1.0);
if let Ok(img) = stitch(page, geometry, Some(scroller), width, height) {
@@ -656,6 +660,39 @@ fn stitch(
}
}
if at_bottom || row_y - origin + band_bottom >= height {
+ // The scroller is at its foot. A document that scrolls a
+ // little further than the viewport (a footer under a 100vh
+ // shell) still holds rows below it: scroll the document by
+ // that much, the scroller kept where it is, and paste the
+ // rows that come into view under the last tile.
+ let document_extra = (geometry.document_height - vh).round();
+ if use_scroller && at_bottom && document_extra >= 1.0 {
+ for &tx in &xs {
+ let args = json!({
+ "x": geometry.capture_origin_x() + tx,
+ "y": row_y,
+ "useScroller": true,
+ "hideFixed": true,
+ "docY": document_extra,
+ });
+ let pos = page.evaluate_value(&format!("({SCROLL_TO_JS})({args})"))?;
+ let sx = pos.get("x").and_then(Value::as_f64).unwrap_or(0.0);
+ let sy = pos.get("y").and_then(Value::as_f64).unwrap_or(0.0);
+ let wy = pos.get("docY").and_then(Value::as_f64).unwrap_or(0.0).round();
+ if wy < 1.0 || (sy - row_y).abs() >= 1.0 {
+ break;
+ }
+ let tile = decode_png(&page.screenshot_viewport_png()?)
+ .ok_or_else(|| CdpError::new("could not decode a viewport tile"))?;
+ if tile.width() != vw.round() as u32 || tile.height() != vh.round() as u32 {
+ return Err(CdpError::new("a viewport tile does not match the viewport"));
+ }
+ paste(&mut canvas, &tile, sx - geometry.capture_origin_x(), sy - origin + wy, (vh - wy, vh));
+ if sx - geometry.capture_origin_x() + 0.5 < tx {
+ break;
+ }
+ }
+ }
break;
}
previous = Some(row_y);
@@ -880,10 +917,13 @@ mod tests {
assert_eq!(tile_rows(Some(&s), 844.0, true, false), (0.0, 800.0));
assert_eq!(tile_rows(Some(&s), 844.0, false, false), (100.0, 800.0));
assert_eq!(tile_rows(Some(&s), 844.0, false, true), (100.0, 844.0));
- assert_eq!(s.unrolled_height(844.0), 100.0 + 5000.0 + 44.0);
+ assert_eq!(s.unrolled_height(844.0, 844.0), 100.0 + 5000.0 + 44.0);
+ // A document 150px taller than the viewport (a footer under the
+ // shell) adds its rows below the bar.
+ assert_eq!(s.unrolled_height(844.0, 994.0), 100.0 + 5000.0 + 44.0 + 150.0);
// Rects measured with the scroller at 300 start 300px earlier.
let scrolled = Scroller { scroll_top: 300.0, ..s };
- assert_eq!(scrolled.unrolled_height(844.0), 100.0 + 4700.0 + 44.0);
+ assert_eq!(scrolled.unrolled_height(844.0, 844.0), 100.0 + 4700.0 + 44.0);
// A body scroller as tall as the viewport.
let body = Scroller {
top: 0.0,
@@ -891,7 +931,7 @@ mod tests {
scroll_height: 6990.0,
scroll_top: 0.0,
};
- assert_eq!(body.unrolled_height(844.0), 6990.0);
+ assert_eq!(body.unrolled_height(844.0, 844.0), 6990.0);
assert_eq!(tile_rows(Some(&body), 844.0, false, false), (0.0, 844.0));
}
diff --git a/crates/browser/src/lib.rs b/crates/browser/src/lib.rs
index 0dda0749f..0032f2ad9 100644
--- a/crates/browser/src/lib.rs
+++ b/crates/browser/src/lib.rs
@@ -836,11 +836,23 @@ fn hand_over(results: &mut [RawResult], handed: &[bool]) {
/// r6-t5-unread-pixel-verdicts). Its text is unchanged. Only the verdicts
/// `hand_over` moved to the visual-contrast origin are touched: the scan
/// origin is what a replay reproduces, and a replay has no pixels.
-fn settle_handed_over(results: &mut Vec<RawResult>, superseded: &[String]) {
+///
+/// A selector that names several elements (a repeated id) is told apart by
+/// its match (`[n, count]`): `match_of` gives a result's, and a pixel verdict
+/// on one copy leaves the verdict on another standing.
+fn settle_handed_over(
+ results: &mut Vec<RawResult>,
+ superseded: &[CandidateKey],
+ match_of: impl Fn(&RawResult) -> Option<Value>,
+) {
let handed = |r: &RawResult| r.origin == origin::VISUAL_CONTRAST && r.id == "low-contrast";
if !superseded.is_empty() {
results.retain(|r| {
- !(handed(r) && r.selector.as_deref().is_some_and(|s| superseded.iter().any(|x| x == s)))
+ !(handed(r)
+ && r.selector.as_deref().is_some_and(|s| {
+ let m = match_of(r);
+ superseded.iter().any(|k| k.names(s, m.as_ref()))
+ }))
});
}
for r in results.iter_mut().filter(|r| handed(r)) {
@@ -971,32 +983,78 @@ fn check_validity(
Ok((response, probe, verdict))
}
-/// The consent-wall verdict for a page whose consent manager arrived after
-/// the load-time validity check, with the probe it was read from. `None`
-/// when the page is not a consent wall now, or the probe failed (the hide
-/// pass then runs as before).
-fn late_consent_wall(page: &mut Page<'_>) -> Option<(PageProbe, PageValidity)> {
- // The first hide pass's rules are on: a root that was an empty stub then
+/// What a late consent pass ([`late_consent_pass`]) found.
+enum LateConsent {
+ /// The page is a consent wall now, with the probe it was read from.
+ Wall(PageProbe, PageValidity),
+ /// It is not; `changed` is whether the hide step altered the page.
+ Clear { changed: bool },
+}
+
+/// The consent-wall check and the hide step for a manager that arrived after
+/// the load-time validity check, in one evaluation: discovery,
+/// classification and hiding read the same page, so a manager inserted in
+/// between can never be hidden without being asked whether it is a wall.
+/// The hide step runs either way (a wall is refused, so what it hid does not
+/// matter); the verdict is read in Rust off the probe it returns. A failed
+/// evaluation falls back to the hide step alone, which is best-effort as
+/// before.
+fn late_consent_pass(page: &mut Page<'_>, consent: &mut ConsentReport) -> LateConsent {
+ // The earlier passes' rules are on: a root that was an empty stub then
// is hidden by them now, though it holds the wall. The probe reads the
// page with them off, in one task, so nothing paints in between.
- // The same goes for the inline hides that pass stamped on a manager
+ // The same goes for the inline hides those passes stamped on a manager
// whose own inline `!important` outranked the rules, while they are still
- // its own: a manager that has since set its own display (closing its
- // dialog) keeps what it set.
+ // theirs ([`consent::STAMP_IS_OURS_JS`]): a manager that has since set its
+ // own display (closing its dialog) keeps what it set. The probe only runs
+ // when a manager's root is in the page, since it is a wall check.
+ let roots: Vec<&str> = consent::CONSENT_MANAGERS.iter().flat_map(|m| m.roots.iter().copied()).collect();
let expr = format!(
- "(() => {{ const s = document.getElementById({id}); const marked = Array.from(document.querySelectorAll('[' + {mark} + ']')).filter(el => el.style.getPropertyValue('display') === 'none' && el.style.getPropertyPriority('display') === 'important'); const put = marked.map(el => {{ let prev = ['', '']; try {{ prev = JSON.parse(el.getAttribute({mark})); }} catch (e) {{}} if (prev[0]) el.style.setProperty('display', prev[0], prev[1]); else el.style.removeProperty('display'); return el; }}); if (s) s.disabled = true; try {{ return {probe}; }} finally {{ if (s) s.disabled = false; for (const el of put) el.style.setProperty('display', 'none', 'important'); }} }})()",
+ "(() => {{ const roots = {roots}; let any = false; for (const sel of roots) {{ try {{ if (document.querySelector(sel)) {{ any = true; break; }} }} catch (e) {{}} }} let probe = null; if (any) {{ try {{ probe = (() => {{ const s = document.getElementById({id}); const marked = Array.from(document.querySelectorAll('[' + {mark} + ']')).filter({ours}); const put = marked.map(el => {{ let prev = ['', '']; try {{ prev = JSON.parse(el.getAttribute({mark})); }} catch (e) {{}} if (prev[0]) el.style.setProperty('display', prev[0], prev[1]); else el.style.removeProperty('display'); return el; }}); if (s) s.disabled = true; try {{ return {probe}; }} finally {{ if (s) s.disabled = false; for (const el of put) el.style.setProperty('display', 'none', 'important'); }} }})(); }} catch (e) {{ probe = null; }} }} const hide = {hide}; return {{ probe, hide }}; }})()",
+ roots = serde_json::json!(roots),
id = serde_json::json!(consent::HIDE_STYLE_ID),
mark = serde_json::json!(consent::INLINE_HIDE_MARK),
+ ours = consent::STAMP_IS_OURS_JS,
probe = validity::probe_js(),
+ hide = consent::hide_js(),
);
- let raw = page.evaluate_value(&expr).ok()?;
- let probe = PageProbe::from_value(&raw);
- if probe.consent.is_empty() {
- return None;
+ let raw = match page.evaluate_value(&expr) {
+ Ok(v) => v,
+ Err(_) => return LateConsent::Clear { changed: hide_consent_banners(page, consent) },
+ };
+ let hide = raw.get("hide").cloned().unwrap_or(Value::Null);
+ consent.merge(&hide);
+ let changed = hide.get("changed").and_then(Value::as_bool).unwrap_or(false);
+ if let Some(probe) = raw.get("probe").filter(|p| p.is_object()).map(PageProbe::from_value) {
+ if !probe.consent.is_empty() {
+ let verdict = validity::classify_with(None, &probe, true);
+ if matches!(verdict, PageValidity::Blocked { kind: validity::BlockKind::ConsentWall, .. }) {
+ return LateConsent::Wall(probe, verdict);
+ }
+ }
+ }
+ LateConsent::Clear { changed }
+}
+
+/// The refusal for a page [`late_consent_pass`] found to be a consent wall:
+/// the error a plain scan returns, or, for an evidence scan, the probe and
+/// verdict recorded beside an empty finding list.
+fn refuse_late_wall(
+ page: &mut Page<'_>,
+ evidence: Option<(&mut Evidence, &EvidenceRequest)>,
+ probe: PageProbe,
+ verdict: PageValidity,
+) -> Result<Vec<RawResult>, EngineError> {
+ let message = verdict.error_message().unwrap_or_default();
+ match evidence {
+ None => Err(EngineError::new(message)),
+ Some((ev, request)) => {
+ ev.probe = Some(probe);
+ ev.validity = Some(verdict);
+ capture_post_scan(page, ev, request, &[], &Map::new());
+ Ok(Vec::new())
+ }
}
- let verdict = validity::classify_with(None, &probe, true);
- matches!(verdict, PageValidity::Blocked { kind: validity::BlockKind::ConsentWall, .. })
- .then_some((probe, verdict))
}
#[allow(clippy::too_many_arguments)]
@@ -1097,19 +1155,11 @@ fn scan_page_inner(
// banner can be the whole page, so the consent-wall gate runs again
// first: hiding a wall would leave nothing to read and report it clean.
if hide_consent {
- if let Some((probe, verdict)) = late_consent_wall(page) {
- let message = verdict.error_message().unwrap_or_default();
- return match evidence {
- None => Err(EngineError::new(message)),
- Some((ev, request)) => {
- ev.probe = Some(probe);
- ev.validity = Some(verdict);
- capture_post_scan(page, ev, request, &[], &Map::new());
- Ok(Vec::new())
- }
- };
+ if let LateConsent::Wall(probe, verdict) =
+ step(profile, "scan", "hide-consent", url, || late_consent_pass(page, consent))
+ {
+ return refuse_late_wall(page, evidence, probe, verdict);
}
- step(profile, "scan", "hide-consent", url, || hide_consent_banners(page, consent));
}
if hide_overlays {
step(profile, "scan", "hide-overlays", url, || hide_page_overlays(page, overlays));
@@ -1124,8 +1174,11 @@ fn scan_page_inner(
// A banner that arrived around the capture is hidden, and the page
// captured again, so the capture, the live hit tests and the pixel reads
// all see the page without it.
- let consent_changed =
- hide_consent && step(profile, "scan", "hide-consent", url, || hide_consent_banners(page, consent));
+ let consent_changed = hide_consent
+ && match step(profile, "scan", "hide-consent", url, || late_consent_pass(page, consent)) {
+ LateConsent::Wall(probe, verdict) => return refuse_late_wall(page, evidence, probe, verdict),
+ LateConsent::Clear { changed } => changed,
+ };
let overlays_changed =
hide_overlays && step(profile, "scan", "hide-overlays", url, || hide_page_overlays(page, overlays));
if consent_changed || overlays_changed {
@@ -1183,6 +1236,7 @@ fn scan_page_inner(
// content-hidden-at-rest: what is still hidden once the reveal handlers
// have run, measured over the same post-reveal capture.
let mut unstarted: Option<(f64, Vec<String>)> = None;
+ let mut probed = false;
let hidden = step_findings(profile, "scan", "content-hidden-at-rest", url, || {
let mut facts = evidence.as_mut().map(|(ev, _)| &mut ev.scan_facts);
let _ = base.take_scroll_probes();
@@ -1202,6 +1256,7 @@ fn scan_page_inner(
if probes.is_empty() {
break;
}
+ probed = true;
let answers = step(profile, "scan", "scroll-probe", url, || {
snapshot_engine::probe_shown_on_scroll(page, &probes)
})
@@ -1230,6 +1285,23 @@ fn scan_page_inner(
))
})?;
results.extend(hidden);
+ // The scroll probe scrolled the page after every pre-capture pass, and a
+ // manager or a tour that injects on scroll would now sit over the page
+ // for the pixel pass's hit tests and shots. The late consent check and
+ // the hide steps run once more; the capture the rule pass read predates
+ // them, so it stands.
+ if probed {
+ if hide_consent {
+ if let LateConsent::Wall(probe, verdict) =
+ step(profile, "scan", "hide-consent", url, || late_consent_pass(page, consent))
+ {
+ return refuse_late_wall(page, evidence, probe, verdict);
+ }
+ }
+ if hide_overlays {
+ step(profile, "scan", "hide-overlays", url, || hide_page_overlays(page, overlays));
+ }
+ }
if let Some(note) = unstarted.and_then(|(chars, samples)| unstarted_slider_note(url, chars, &samples)) {
notes.push(note);
}
@@ -1250,7 +1322,9 @@ fn scan_page_inner(
.map_err(cdp_err)?;
let (mut visual, superseded) =
run_visual_contrast_fallback(page, &analyses, &serialized_groups, viewport, profile, url)?;
- settle_handed_over(&mut results, &superseded);
+ settle_handed_over(&mut results, &superseded, |r| {
+ repeated_match(&base, r.selector.as_deref()?, r.scan_el?)
+ });
for r in visual.iter_mut() {
tag_widget_vendor(&base, r);
}
@@ -1602,6 +1676,54 @@ fn reveal_sweep(page: &mut Page<'_>) -> Result<(), CdpError> {
Ok(())
}
+/// A visual-contrast candidate's identity: its selector, and its match
+/// (`[n, count]`) when the selector named several elements in the capture (a
+/// repeated id), so copies sharing a selector are not taken for one another.
+#[derive(Debug, Clone, PartialEq)]
+struct CandidateKey {
+ selector: String,
+ matched: Option<Value>,
+}
+
+impl CandidateKey {
+ /// A candidate's or an analysis's key; `None` without a selector.
+ fn of(v: &Value) -> Option<CandidateKey> {
+ Some(CandidateKey {
+ selector: selector_of(v)?,
+ matched: v.get("match").filter(|m| m.is_array()).cloned(),
+ })
+ }
+
+ /// Whether this key names `selector` at `matched`. Without a match on
+ /// either side (a selector that named one element), the selector decides.
+ fn names(&self, selector: &str, matched: Option<&Value>) -> bool {
+ self.selector == selector
+ && match (&self.matched, matched) {
+ (Some(a), Some(b)) => a == b,
+ _ => true,
+ }
+ }
+
+ fn names_value(&self, v: &Value) -> bool {
+ selector_of(v).is_some_and(|s| self.names(&s, v.get("match").filter(|m| m.is_array())))
+ }
+}
+
+/// The match [`impeccable_core::browser::visual`] records for a candidate on
+/// `el` (`[n, count]` among the capture's matches of `selector`), for a
+/// selector anchored on an id that names several elements; `None` otherwise.
+fn repeated_match(dom: &dyn Dom, selector: &str, el: ElId) -> Option<Value> {
+ if !selector.contains('#') {
+ return None;
+ }
+ let matches = dom.query_all(None, selector).ok()?;
+ if matches.len() < 2 {
+ return None;
+ }
+ let n = matches.iter().position(|m| *m == el)?;
+ Some(json!([n, matches.len()]))
+}
+
/// The findings the analytic and canvas analyses give, and the routed
/// selectors whose element verdict they replace. A selector the element pass
/// already reported keeps that report, except where the element pass handed
@@ -1611,15 +1733,15 @@ fn reveal_sweep(page: &mut Page<'_>) -> Result<(), CdpError> {
fn analysis_findings(
browser_analyses: &[Value],
existing_low_contrast: &[String],
- routed: &[String],
-) -> (Vec<RawResult>, Vec<String>) {
- let is_routed = |sel: Option<&str>| routed.iter().any(|s| Some(s.as_str()) == sel);
+ routed: &[CandidateKey],
+) -> (Vec<RawResult>, Vec<CandidateKey>) {
+ let is_routed = |v: &Value| routed.iter().any(|k| k.names_value(v));
let findings = browser_analyses
.iter()
.filter(|r| {
let sel = r.get("selector").and_then(Value::as_str);
truthy(r.get("finding"))
- && (is_routed(sel) || !existing_low_contrast.iter().any(|s| Some(s.as_str()) == sel))
+ && (is_routed(r) || !existing_low_contrast.iter().any(|s| Some(s.as_str()) == sel))
})
.filter_map(|r| r.get("finding").map(|f| (f, selector_of(r))))
.map(|(f, selector)| RawResult {
@@ -1628,13 +1750,12 @@ fn analysis_findings(
..RawResult::new(origin::VISUAL_CONTRAST, js_str(f.get("id")), js_str(f.get("snippet")))
})
.collect();
- let mut superseded: Vec<String> = Vec::new();
+ let mut superseded: Vec<CandidateKey> = Vec::new();
for r in browser_analyses {
- let sel = r.get("selector").and_then(Value::as_str);
let resolved = matches!(r.get("status").and_then(Value::as_str), Some("fail") | Some("pass"));
- if let Some(s) = sel.filter(|s| resolved && !s.is_empty() && is_routed(Some(s))) {
- if !superseded.iter().any(|x| x == s) {
- superseded.push(s.to_string());
+ if let Some(key) = CandidateKey::of(r).filter(|_| resolved && is_routed(r)) {
+ if !superseded.contains(&key) {
+ superseded.push(key);
}
}
}
@@ -1652,16 +1773,16 @@ fn run_visual_contrast_fallback(
viewport: Viewport,
profile: Option<&DetectorProfile>,
target: &str,
-) -> Result<(Vec<RawResult>, Vec<String>), EngineError> {
+) -> Result<(Vec<RawResult>, Vec<CandidateKey>), EngineError> {
// Text the element pass hands over rather than scores (see
// `visual::routed_reason`): its element verdict does not keep the pixels
// from reading it, and the pixels' verdict replaces that one.
- let routed: Vec<String> = browser_analyses
+ let routed: Vec<CandidateKey> = browser_analyses
.iter()
.filter(|a| a.get("routed").is_some_and(|r| !r.is_null()))
- .filter_map(|a| a.get("selector").and_then(Value::as_str))
- .map(String::from)
+ .filter_map(CandidateKey::of)
.collect();
+ let is_routed = |v: &Value| routed.iter().any(|k| k.names_value(v));
let existing_low_contrast: Vec<String> = serialized_groups
.iter()
.filter(|g| {
@@ -1686,7 +1807,7 @@ fn run_visual_contrast_fallback(
// the candidate list; when there are none, there are none to collect.
let candidates: &[Value] = browser_analyses;
- let browser_resolved: Vec<String> = browser_analyses
+ let browser_resolved: Vec<CandidateKey> = browser_analyses
.iter()
.filter(|r| {
matches!(
@@ -1694,9 +1815,7 @@ fn run_visual_contrast_fallback(
Some("fail") | Some("pass")
)
})
- .filter_map(|r| r.get("selector").and_then(Value::as_str))
- .filter(|s| !s.is_empty())
- .map(String::from)
+ .filter_map(CandidateKey::of)
.collect();
let filtered: Vec<&Value> = candidates
.iter()
@@ -1705,10 +1824,13 @@ fn run_visual_contrast_fallback(
(!existing_low_contrast
.iter()
.any(|s| Some(s.as_str()) == sel)
- || routed.iter().any(|s| Some(s.as_str()) == sel))
- && !browser_resolved.iter().any(|s| Some(s.as_str()) == sel)
+ || is_routed(c))
+ && !browser_resolved.iter().any(|k| k.names_value(c))
})
.collect();
+ // Where a clip's x 0 sits: the left edge of a right-to-left page's
+ // overflow, asked once for every candidate.
+ let origin_x = if filtered.is_empty() { 0.0 } else { screenshot_contrast::scroll_origin_x(page) };
if !filtered.is_empty() {
// The pixel pass reads one box twice, once with the text painted and
// once without. A frame that advances between the two shots turns
@@ -1725,7 +1847,7 @@ fn run_visual_contrast_fallback(
for candidate in filtered {
let sel = candidate.get("selector").and_then(Value::as_str);
// A read the first budget's rules would not have made.
- let extra = routed.iter().any(|s| Some(s.as_str()) == sel)
+ let extra = is_routed(candidate)
&& (candidate.get("reasons").and_then(Value::as_array).is_some_and(|rs| {
rs.iter().any(|r| matches!(r.as_str(), Some("unread layer") | Some("text outline")))
}) || existing_low_contrast.iter().any(|s| Some(s.as_str()) == sel));
@@ -1739,6 +1861,7 @@ fn run_visual_contrast_fallback(
page,
candidate,
viewport.width as f64,
+ origin_x,
)
.map_err(cdp_err)?;
measured = m.measured;
@@ -1765,11 +1888,9 @@ fn run_visual_contrast_fallback(
routed_misses += 1;
}
}
- if measured {
- if let Some(s) = sel {
- if routed.iter().any(|r| r == s) {
- superseded.push(s.to_string());
- }
+ if measured && is_routed(candidate) {
+ if let Some(key) = CandidateKey::of(candidate) {
+ superseded.push(key);
}
}
findings.extend(result);
@@ -1806,13 +1927,45 @@ mod tests {
json!({"selector": "#vector", "routed": "unread layer", "status": "unresolved"}),
];
let existing: Vec<String> = ["#photo-copy", "#photo-ok", "#plain", "#vector"].iter().map(|s| s.to_string()).collect();
- let routed: Vec<String> = ["#photo-copy", "#photo-ok", "#vector"].iter().map(|s| s.to_string()).collect();
+ let routed: Vec<CandidateKey> = analyses.iter().filter(|a| a.get("routed").is_some()).filter_map(CandidateKey::of).collect();
let (findings, superseded) = analysis_findings(&analyses, &existing, &routed);
let sels: Vec<&str> = findings.iter().filter_map(|f| f.selector.as_deref()).collect();
assert_eq!(sels, vec!["#photo-copy"]);
+ let superseded: Vec<&str> = superseded.iter().map(|k| k.selector.as_str()).collect();
assert_eq!(superseded, vec!["#photo-copy", "#photo-ok"]);
}
+ /// Two copies of a repeated id are two candidates: the copy an analysis
+ /// resolved is superseded, its unresolved twin stays routed to the
+ /// pixels, and the element pass's verdict on the twin stands.
+ #[test]
+ fn copies_of_a_repeated_id_are_settled_apart() {
+ let analyses = vec![
+ json!({"selector": "#hero > p", "match": [0, 2], "routed": "unread layer", "status": "pass"}),
+ json!({"selector": "#hero > p", "match": [1, 2], "routed": "unread layer", "status": "unresolved"}),
+ ];
+ let existing = vec!["#hero > p".to_string()];
+ let routed: Vec<CandidateKey> = analyses.iter().filter_map(CandidateKey::of).collect();
+ let (_, superseded) = analysis_findings(&analyses, &existing, &routed);
+ assert_eq!(superseded, vec![CandidateKey { selector: "#hero > p".into(), matched: Some(json!([0, 2])) }]);
+ // The unresolved copy is not taken for the resolved one.
+ assert!(!superseded[0].names_value(&analyses[1]));
+ assert!(superseded[0].names_value(&analyses[0]));
+ // A selector that named one element has no match, and the selector decides.
+ let single = CandidateKey::of(&json!({"selector": "#solo"})).unwrap();
+ assert!(single.names("#solo", Some(&json!([1, 2]))));
+
+ let verdict = |n: u64| RawResult {
+ selector: Some("#hero > p".into()),
+ ..RawResult::new(origin::VISUAL_CONTRAST, "low-contrast".into(), format!("copy {n}"))
+ };
+ let mut results = vec![verdict(0), verdict(1)];
+ let copy_of = |r: &RawResult| r.snippet.strip_prefix("copy ").and_then(|n| n.parse::<u64>().ok());
+ settle_handed_over(&mut results, &superseded, |r| copy_of(r).map(|n| json!([n, 2])));
+ let left: Vec<(&str, &str)> = results.iter().map(|r| (r.snippet.as_str(), r.severity.as_str())).collect();
+ assert_eq!(left, vec![("copy 1", "advisory")]);
+ }
+
#[test]
fn ad_tech_errors_never_take_a_counted_errors_slot() {
let prebid = |n: u32| (format!("Uncaught Error: bid {n}"), Some(format!("at https://example.com/prebid/prebid-p{n}.js:1:1")));
@@ -1850,7 +2003,7 @@ mod tests {
result(origin::SCAN, "low-contrast", "#scored", ""),
result(origin::SCAN, "tiny-text", "#unread", ""),
];
- settle_handed_over(&mut results, &["#read".to_string()]);
+ settle_handed_over(&mut results, &[CandidateKey { selector: "#read".into(), matched: None }], |_| None);
let summary: Vec<(&str, &str, &str)> =
results.iter().map(|r| (r.origin, r.snippet.as_str(), r.severity.as_str())).collect();
assert_eq!(
diff --git a/crates/browser/src/screenshot_contrast.rs b/crates/browser/src/screenshot_contrast.rs
index 3a1d81c89..dcdc06d75 100644
--- a/crates/browser/src/screenshot_contrast.rs
+++ b/crates/browser/src/screenshot_contrast.rs
@@ -248,7 +248,92 @@ pub fn capture_visual_contrast_candidate(
candidate: &Value,
viewport_width: f64,
) -> CdpResult<Option<RawFinding>> {
- Ok(measure_visual_contrast_candidate(page, candidate, viewport_width)?.finding)
+ let origin_x = scroll_origin_x(page);
+ Ok(measure_visual_contrast_candidate(page, candidate, viewport_width, origin_x)?.finding)
+}
+
+/// The furthest left the document scrolls, in document coordinates: 0, or
+/// negative on a page that scrolls from the right (a right-to-left page wider
+/// than the viewport keeps its overflow at negative x). A beyond-viewport
+/// clip's x 0 is that edge, so a candidate's document x moves right by the
+/// overflow's width. Asked the way the full-page screenshot asks it
+/// (`crate::fullpage`), by scrolling there and straight back in one task.
+pub fn scroll_origin_x(page: &mut Page<'_>) -> f64 {
+ page.evaluate_value(SCROLL_ORIGIN_JS)
+ .ok()
+ .and_then(|v| v.as_f64())
+ .filter(|x| x.is_finite())
+ .map_or(0.0, |x| x.min(0.0))
+}
+
+const SCROLL_ORIGIN_JS: &str = r#"(() => {
+ const se = document.scrollingElement || document.documentElement;
+ if (!se || se.scrollWidth <= se.clientWidth + 1) return 0;
+ const sx = window.scrollX;
+ const sy = window.scrollY;
+ window.scrollTo({ left: -se.scrollWidth, top: sy, behavior: 'instant' });
+ const origin = Math.min(0, window.scrollX);
+ if (window.scrollX !== sx) window.scrollTo({ left: sx, top: sy, behavior: 'instant' });
+ return origin;
+})()"#;
+
+/// The candidate's clip in document coordinates. The collector clamps a
+/// clip's x at 0, which on a page that scrolls from the right cuts every
+/// candidate in the overflow left of the viewport to the same x: there the
+/// box the collector measured is read again, live, for its own x. That box
+/// is the union of the element's own text lines (the capture's direct text
+/// rect), or its border box when it has none, so x, width and height still
+/// describe one box.
+fn document_clip(page: &mut Page<'_>, candidate: &Value, origin_x: f64) -> Option<Value> {
+ let clip = candidate.get("clip")?;
+ if !(origin_x < 0.0) || !clip.is_object() || num(clip.get("x")) > 0.0 {
+ return Some(clip.clone());
+ }
+ let selector = candidate.get("selector").and_then(Value::as_str).filter(|s| !s.is_empty());
+ let left = selector.and_then(|selector| {
+ page.evaluate_value(&format!(
+ "({LIVE_TEXT_LEFT_JS})(({PICK_CANDIDATE_JS})({}, {}))",
+ json!(selector),
+ candidate.get("match").cloned().unwrap_or(Value::Null)
+ ))
+ .ok()?
+ .as_f64()
+ .filter(|x| x.is_finite())
+ });
+ let mut clip = clip.clone();
+ if let (Some(left), Some(obj)) = (left, clip.as_object_mut()) {
+ obj.insert("x".into(), json!((left - 2.0).floor()));
+ }
+ Some(clip)
+}
+
+/// `el => x`: the document x of the left edge of an element's own text lines
+/// (its direct text nodes, as the capture's direct text rect reads them), or
+/// of its border box when it has none; `null` without an element.
+const LIVE_TEXT_LEFT_JS: &str = r#"(el => {
+ if (!el) return null;
+ let left = Infinity;
+ for (const child of el.childNodes) {
+ if (child.nodeType !== 3 || !(child.textContent || '').trim()) continue;
+ const range = document.createRange();
+ range.selectNodeContents(child);
+ for (const r of range.getClientRects()) if (r.width >= 1 && r.height >= 1) left = Math.min(left, r.left);
+ }
+ if (!Number.isFinite(left)) left = el.getBoundingClientRect().left;
+ return left + window.scrollX;
+})"#;
+
+/// A candidate's document clip as a `Page.captureScreenshot` clip, whose x 0
+/// is the left edge of what the document scrolls ([`scroll_origin_x`]).
+fn capture_clip(clip: Option<&Value>, origin_x: f64) -> Option<Value> {
+ let mut clip = clip?.clone();
+ if origin_x < 0.0 {
+ if let Some(obj) = clip.as_object_mut() {
+ let x = num(obj.get("x"));
+ obj.insert("x".into(), json!(x - origin_x));
+ }
+ }
+ Some(clip)
}
/// What the pixel pass made of one candidate: its finding, if the text
@@ -265,6 +350,7 @@ pub fn measure_visual_contrast_candidate(
page: &mut Page<'_>,
candidate: &Value,
viewport_width: f64,
+ origin_x: f64,
) -> CdpResult<PixelMeasure> {
let reasons: Vec<String> = candidate
.get("reasons")
@@ -276,14 +362,17 @@ pub fn measure_visual_contrast_candidate(
if visual::pixel_contrast_blocked(&reasons).is_some() {
return Ok(PixelMeasure::default());
}
- let Some(clip) = sanitize_screenshot_clip(candidate.get("clip"), Some(viewport_width)) else {
+ let Some(clip) = sanitize_screenshot_clip(
+ capture_clip(document_clip(page, candidate, origin_x).as_ref(), origin_x).as_ref(),
+ Some(viewport_width),
+ ) else {
return Ok(PixelMeasure::default());
};
// A candidate past the document's content box (text inside an element the
// page scrolls instead of its document) paints nothing in a beyond-viewport
// capture, so both shots would read blank. Scroll it into view, read its
// pixels there, and put the scroll back.
- let brought = bring_into_view(page, candidate, &clip, viewport_width);
+ let brought = bring_into_view(page, candidate, &clip, viewport_width, origin_x);
let (candidate, clip) = match &brought {
Some((moved, moved_clip)) => (moved, *moved_clip),
None => (candidate, clip),
@@ -357,6 +446,7 @@ fn bring_into_view(
candidate: &Value,
clip: &Clip,
viewport_width: f64,
+ origin_x: f64,
) -> Option<(Value, Clip)> {
let content = page.content_size().ok()?;
if !clip_beyond_content(clip, content) {
@@ -379,14 +469,14 @@ fn bring_into_view(
let n = |key: &str| v.get(key).and_then(Value::as_f64).filter(|f| f.is_finite());
let live = match (n("x"), n("y"), n("width"), n("height")) {
(Some(x), Some(y), Some(w), Some(h)) => json!({
- "x": math_max(0.0, (x - 2.0).floor()),
+ "x": (x - 2.0).floor(),
"y": math_max(0.0, (y - 2.0).floor()),
"width": math_max(1.0, (w + 4.0).ceil()),
"height": math_max(1.0, (h + 4.0).ceil()),
}),
_ => Value::Null,
};
- let Some(moved_clip) = sanitize_screenshot_clip(Some(&live), Some(viewport_width)) else {
+ let Some(moved_clip) = sanitize_screenshot_clip(capture_clip(Some(&live), origin_x).as_ref(), Some(viewport_width)) else {
let _ = page.evaluate(RESTORE_SCROLL_JS);
return None;
};
@@ -637,6 +727,17 @@ mod tests {
assert!(sanitize_screenshot_clip(Some(&Value::Null), None).is_none());
}
+ #[test]
+ fn a_right_to_left_overflow_moves_the_clip() {
+ let clip = json!({ "x": -40.0, "y": 300.0, "width": 200.0, "height": 24.0 });
+ // A page that scrolls from the left keeps the document x.
+ assert_eq!(capture_clip(Some(&clip), 0.0), Some(clip.clone()));
+ // 321px of overflow left of the viewport: document x -40 is clip x 281.
+ let c = sanitize_screenshot_clip(capture_clip(Some(&clip), -321.0).as_ref(), Some(390.0)).unwrap();
+ assert_eq!((c.x, c.y), (281.0, 300.0));
+ assert_eq!(capture_clip(None, -321.0), None);
+ }
+
#[test]
fn clips_past_the_content_box_are_brought_into_view() {
let clip = |x: f64, y: f64, width: f64, height: f64| Clip { x, y, width, height };
diff --git a/crates/browser/tests/consent_hiding.rs b/crates/browser/tests/consent_hiding.rs
index d0d7ee557..a71955ef3 100644
--- a/crates/browser/tests/consent_hiding.rs
+++ b/crates/browser/tests/consent_hiding.rs
@@ -21,6 +21,12 @@
//! is refused; a short page under a shadow-root banner, or one appended
//! outside <body>, is scanned, as is a page whose late banner closed
//! itself; a late banner on a root the first pass hid inline is reported.
+//! - A form two web components down counts as the page; a late banner its
+//! manager closed by rewriting its style to the stamped
+//! `display: none !important` stays closed; dialogs a fixed layer parks
+//! past the viewport, or a collapsed wrapper clips away, are not showing,
+//! while a fixed bar a transformed ancestor holds below the fold is; and a
+//! banner that arrives during the scroll probe is hidden after it.
use std::collections::HashMap;
use std::io::{Read, Write};
@@ -455,3 +461,63 @@ fn a_frame_in_the_managers_shadow_root_is_a_wall() {
let err = engine.detect_url(&url, &ScanOptions::default()).expect_err("a framed consent wall must not scan");
assert!(err.message.starts_with("the page is a consent wall, not the site (consent manager Sourcepoint, "), "{}", err.message);
}
+
+#[test]
+fn a_form_in_a_nested_web_component_under_a_banner_is_scanned() {
+ let Some(engine) = engine() else { return };
+ let port = serve();
+ let url = format!("http://127.0.0.1:{port}/shadow-nested-form-page.html");
+ engine
+ .detect_url_scan(&url, &ScanOptions::default())
+ .expect("a form two shadow roots down is the page");
+}
+
+#[test]
+fn a_late_banner_closed_with_the_stamped_value_is_not_a_wall() {
+ let Some(engine) = engine() else { return };
+ let port = serve();
+ let url = format!("http://127.0.0.1:{port}/late-closed-attr-banner.html");
+ engine
+ .detect_url_scan(&url, &ScanOptions::default())
+ .expect("a banner its manager closed with display: none !important leaves the page");
+}
+
+#[test]
+fn closed_dialogs_parked_offscreen_or_clipped_are_not_showing() {
+ let Some(engine) = engine() else { return };
+ let port = serve();
+ let url = format!("http://127.0.0.1:{port}/parked-banner-page.html");
+ let mut browser = engine.launch().expect("launch");
+ let (_, evidence) =
+ detect_url_evidence(&mut browser, &url, &ScanOptions::default(), "load", 100, &EvidenceRequest::default())
+ .expect("a page whose consent dialogs are parked away is not a wall");
+ browser.close();
+ assert_eq!(evidence.validity.as_ref().unwrap().to_value()["status"], "ok");
+ assert!(evidence.consent.as_ref().expect("consent report").hidden.is_empty());
+}
+
+#[test]
+fn a_banner_the_scroll_probe_brings_in_is_hidden() {
+ let Some(engine) = engine() else { return };
+ let port = serve();
+ let url = format!("http://127.0.0.1:{port}/after-scroll-probe-banner.html");
+ let scan = engine.detect_url_scan(&url, &ScanOptions::default()).expect("scan");
+ assert!(
+ scan.notes.iter().any(|n| n.starts_with("Hid the OneTrust consent banner")),
+ "{:?}",
+ scan.notes
+ );
+}
+
+#[test]
+fn a_fixed_banner_a_transformed_ancestor_holds_is_showing() {
+ let Some(engine) = engine() else { return };
+ let port = serve();
+ let url = format!("http://127.0.0.1:{port}/held-fixed-banner.html");
+ let mut browser = engine.launch().expect("launch");
+ let (_, evidence) =
+ detect_url_evidence(&mut browser, &url, &ScanOptions::default(), "load", 100, &EvidenceRequest::default())
+ .expect("scan");
+ browser.close();
+ assert_eq!(evidence.consent.as_ref().expect("consent report").hidden, vec!["OneTrust"]);
+}
diff --git a/crates/browser/tests/fullpage_screenshot.rs b/crates/browser/tests/fullpage_screenshot.rs
index 5139e7cb6..b60813377 100644
--- a/crates/browser/tests/fullpage_screenshot.rs
+++ b/crates/browser/tests/fullpage_screenshot.rs
@@ -4,7 +4,8 @@
//! - A tall document paints to its foot, and a wide one to its right edge.
//! - A page whose body scrolls (the document is one viewport tall) is
//! captured by scrolling the body, and the pixel contrast pass reads the
-//! text below its fold.
+//! text below its fold. A footer under a 100vh shell that scrolls its own
+//! frame follows the frame's content.
//! - Rows a feed renders only once they are scrolled to appear in the
//! screenshot.
//! - An element past the screenshot cut gets a viewport shot of its own.
@@ -504,3 +505,66 @@ fn a_shell_inside_a_body_margin_is_captured_by_scrolling_the_shell() {
let p = img.get_pixel(40, 8 + 3000 + 30).0;
assert!(p[1] > 90 && p[0] < 60 && p[2] < 110, "the marker below the fold is missing: {p:?}");
}
+
+/// A 100vh app shell that scrolls its own frame, with a footer below it, so
+/// the document scrolls the footer's height: under a quarter viewport, so
+/// the frame is captured, and the footer has to follow the frame's content.
+/// Served inline, like the margin shell.
+const SHELL_FOOTER_PAGE: &str = r#"<!DOCTYPE html>
+<html lang="en"><head><meta charset="UTF-8"><title>Shell footer</title>
+<style>
+ body { margin: 0; background: #ffffff; }
+ .shell { height: 100vh; overflow: auto; }
+ .content { height: 3000px; background: #ffffff; }
+ .footer { height: 150px; background: #0a7d3b; }
+</style></head>
+<body>
+ <div class="shell"><div class="content"></div></div>
+ <div class="footer"></div>
+</body></html>"#;
+
+#[test]
+fn a_footer_under_a_scrolled_shell_reaches_the_screenshot() {
+ let Some(engine) = engine() else { return };
+ let port = serve_page(SHELL_FOOTER_PAGE);
+ let options = ScanOptions {
+ viewport: Some((1280, 800)),
+ ..Default::default()
+ };
+ let mut browser = engine.launch().expect("launch");
+ let url = format!("http://127.0.0.1:{port}/");
+ let (_, evidence) = detect_url_evidence(&mut browser, &url, &options, "load", 100, &EvidenceRequest::default())
+ .expect("evidence scan");
+ browser.close();
+ let shot = evidence.screenshot.as_ref().expect("screenshot");
+ assert_eq!(shot.method, impeccable_browser::fullpage::method::STITCHED);
+ assert!(shot.height >= 3140.0, "{}", shot.height);
+ let img = decode(&shot.jpeg_base64);
+ // The shell's content is white to its foot; the footer follows it.
+ let p = img.get_pixel(40, 2900).0;
+ assert!(p[0] > 200 && p[1] > 200, "the shell's content is not white: {p:?}");
+ let p = img.get_pixel(40, 3075).0;
+ assert!(p[1] > 90 && p[0] < 60 && p[2] < 110, "the footer below the shell is missing: {p:?}");
+}
+
+fn serve_page(body: &'static str) -> u16 {
+ let listener = TcpListener::bind("127.0.0.1:0").expect("bind");
+ let port = listener.local_addr().unwrap().port();
+ std::thread::spawn(move || {
+ // One thread per connection, so an idle connection the browser opens
+ // ahead of its request never holds up the one that asks.
+ for mut stream in listener.incoming().flatten() {
+ std::thread::spawn(move || {
+ let mut buf = [0u8; 8192];
+ let _ = stream.read(&mut buf);
+ let head = format!(
+ "HTTP/1.0 200 OK\r\nContent-Type: text/html; charset=utf-8\r\nContent-Length: {}\r\nConnection: close\r\n\r\n",
+ body.len()
+ );
+ let _ = stream.write_all(head.as_bytes());
+ let _ = stream.write_all(body.as_bytes());
+ });
+ }
+ });
+ port
+}
diff --git a/crates/browser/tests/pixel_pass_identity.rs b/crates/browser/tests/pixel_pass_identity.rs
index fc7798ced..d7e8cbb5f 100644
--- a/crates/browser/tests/pixel_pass_identity.rs
+++ b/crates/browser/tests/pixel_pass_identity.rs
@@ -1,5 +1,6 @@
//! The pixel pass measures the element its candidate came from when the page
-//! repeats the id the candidate's selector is anchored on. Rendered by an
+//! repeats the id the candidate's selector is anchored on, and reads a
+//! right-to-left page's pixels where its text paints. Rendered by an
//! installed browser; skips cleanly when there is none.
use std::collections::HashMap;
@@ -70,3 +71,63 @@ fn a_repeated_id_does_not_send_the_pixel_pass_to_a_collapsed_copy() {
"the vector copy past the body scroller's fold was not measured: {pixel:?}"
);
}
+
+/// A right-to-left page wider than the viewport keeps its overflow at
+/// negative document x, and a beyond-viewport clip's x 0 is the left edge of
+/// that overflow. White text on pale vector artwork only the pixel pass can
+/// answer, once inside the first viewport at the right and once in the
+/// overflow at negative x; each clip has to be moved by the scroll origin or
+/// both shots read somewhere else. The overflow copy is short and set at the
+/// right of its padded box, so only its text's own x finds it.
+const RTL_VECTOR_PAGE: &str = r##"<!DOCTYPE html>
+<html lang="he" dir="rtl"><head><meta charset="UTF-8"><title>Right-to-left vector copy</title>
+<style>
+ body { margin: 0; background: #ffffff; color: #111111; font: 16px/1.5 Arial, sans-serif; }
+ .wide { width: 2400px; height: 40px; background: #ffffff; }
+ .vector-panel {
+ position: relative; isolation: isolate; width: 420px; height: 96px; margin: 24px 0 0;
+ background: #1d2330 url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16'><rect width='16' height='16' fill='%231d2330'/><circle cx='8' cy='8' r='3' fill='%23262d3b'/></svg>") repeat;
+ }
+ .vector-panel svg { position: absolute; right: 0; top: 0; z-index: 0; display: block; width: 420px; height: 96px; }
+ .vector-panel p { position: relative; z-index: 1; margin: 0; padding: 24px; width: 372px; font-size: 16px; line-height: 1.6; color: #fdfdfd; }
+ .overflow-row { width: 2400px; }
+ .overflow-row .vector-panel { margin-right: 1400px; }
+</style></head>
+<body>
+ <div class="wide"></div>
+ <div class="vector-panel">
+ <svg viewBox="0 0 420 96" aria-hidden="true"><rect width="420" height="96" fill="#f5f2ea"/></svg>
+ <p id="rtl-vector-copy">White text on pale vector artwork.</p>
+ </div>
+ <div class="overflow-row">
+ <div class="vector-panel">
+ <svg viewBox="0 0 420 96" aria-hidden="true"><rect width="420" height="96" fill="#f5f2ea"/></svg>
+ <p id="rtl-overflow-copy">Pale copy.</p>
+ </div>
+ </div>
+</body></html>"##;
+
+#[test]
+fn a_right_to_left_page_reads_pixels_where_the_text_paints() {
+ let env: HashMap<String, String> = std::env::vars().collect();
+ if impeccable_browser::discovery::find_browser(&env).is_err() {
+ eprintln!("skip: no installed browser found");
+ return;
+ }
+ let port = serve(RTL_VECTOR_PAGE.to_string());
+ let engine = BrowserEngine::new(env);
+ let url = format!("http://127.0.0.1:{port}/");
+ let options = ScanOptions { viewport: Some((1280, 800)), ..Default::default() };
+ let findings = engine.detect_url(&url, &options).expect("scan");
+ for id in ["#rtl-vector-copy", "#rtl-overflow-copy"] {
+ let pixel: Vec<&str> = findings
+ .iter()
+ .filter(|f| f.antipattern == "low-contrast" && f.extras.get("selector").and_then(|v| v.as_str()) == Some(id))
+ .map(|f| f.snippet.as_str())
+ .collect();
+ assert!(
+ pixel.iter().any(|s| s.starts_with("pixel contrast ")),
+ "{id} on a right-to-left page was not measured where it paints: {pixel:?}"
+ );
+ }
+}
diff --git a/docs/CLI-CONTRACT.md b/docs/CLI-CONTRACT.md
index 49fd10fc0..5f0df9877 100644
--- a/docs/CLI-CONTRACT.md
+++ b/docs/CLI-CONTRACT.md
@@ -361,9 +361,9 @@ Optional keys added later by engines (appended after the above): `ignoreValue` (
- **Footer column titles** (corpus decision r5-p29-skipped-heading-footer-titles; static HTML engine and URL engine alike). `skipped-heading` does not report a skip into the footer: the skipped heading is inside `footer`, `[role="contentinfo"]` or `#footer`, and the heading it follows is either outside that footer (the last heading before it) or that footer's first heading when that heading did not itself skip into the footer (a closing call to action inside the footer; a first heading that skipped in is a column title). A skip between two later footer headings reports, and so does every skip outside a footer. A footer built from unmarked `div`s is not recognised and reports as before.
- **Contrast ratios in snippets.** Every `low-contrast` producer (the element text path shared by both engines, which covers links, spans and placeholders, the static engine's `:hover state`, and the URL engine's `browser contrast` sampling and `pixel contrast` passes, verdict and median) prints a ratio against its threshold: one decimal; two when one decimal would round a failing ratio up to the threshold; and those two cut, not rounded, when rounding them would reach it too. A ratio under the bar never prints as the bar: `4.49:1 (need 4.5:1)`, never `4.5:1` or `4.50:1`. A ratio at or above the threshold, such as a median over it, prints one decimal.
- **Page validity gate.** After `goto` (and settle), before injecting anything, the engine classifies the page (`crates/browser/src/validity.rs`) from the main document's final CDP response and an in-page probe (title, visible text length, final URL, challenge-widget markers). Challenge: an `x-amzn-waf-action` header, `cf-mitigated: challenge`, a final URL on a challenge-only host (`perfdrive.com`, `captcha-delivery.com`), or, on a page with at most 3000 characters of visible text, a challenge title prefix ("Just a moment", "Attention Required! | Cloudflare", "Human Verification", "Access Denied", "Radware Bot Manager", "Captcha", ...) or a full-page widget marker (Cloudflare challenge form, PerimeterX, DataDome, Imperva, Akamai, AWS WAF, slider captchas). On a page of any size, a bot manager's challenge sheet laid over the rendered page is a challenge too: HUMAN Security's (PerimeterX's) "Press & hold" check, `#px-captcha-modal` or `#px-captcha-wrapper`, while it is showing (not `display: none`, not `visibility: hidden`, opacity over 0.02) and covers at least half the viewport; the signal reads `overlay human-press-and-hold`, and the probe records `overlays` only when one shows. HTTP error: a final status >= 400 with no challenge signal. A blocked page throws `the page is a bot challenge, not the site (<signals>). Findings would describe the challenge page, so none are reported.` or `the page returned an error (HTTP <status>). Findings would describe the error page, so none are reported.`, which the CLI prints as `Error: ...` and counts as an operational failure (exit 1). A `file://` load has no response, so only the probe signals apply.
- Consent wall: a page where a known consent manager (next item) is showing (its text counted with the text of open shadow roots under its roots, where Usercentrics renders), hiding it would leave next to nothing (fewer than 20 visible characters outside its roots, and no visible form control (`input` other than hidden, `select`, `textarea`, `button`) and no `img`, `svg`, `video`, `canvas`, `iframe`, `object` or `embed` of 10,000 square pixels or more outside them), and the manager holds at least 100 characters or a frame of 10,000 square pixels or more (a message drawn in an iframe, whose text the page cannot read). For this test, text of the manager's that `body.innerText` does not see (rendered in a shadow root, or in a root appended outside `<body>`) is added to the page's visible-text count too (`consentShadowChars`), so the two counts describe the same text; the challenge checks keep the page's own count. It throws `the page is a consent wall, not the site (consent manager <names>, <n> of <total> visible characters outside it, no control or image outside it). Findings would describe the consent dialog, so none are reported.` A short page under an ordinary banner (a sign-in form, a splash page with a button, an image-first page) is scanned. The probe runs before any banner is hidden, and again before the hide pass after the reveal sweep, with the earlier hide rules switched off and its inline hides lifted for that read (an inline hide the manager has since replaced with its own display stays as the manager set it), so a wall that arrives after load, or fills a root that was an empty stub, is refused too (the evidence then carries that later probe). With `--no-consent-hiding` the gate is off and the page is scanned with its banner, which is what that flag asks for. The probe object (evidence) carries `consent` (the names of the managers showing), `consentChars` (visible characters inside them) and `consentOutside` (visible controls and sizable media outside them, counted up to 20).
- - **Consent banners** (Rust engine). A consent banner covers copy a visitor reads once they dismiss it: text under it was skipped as covered or scored against the banner, and the banner's own text was scored as the site's. After the validity gate, again after the reveal sweep (so a banner injected after load or on the first scroll is caught before the capture), and once more right after the capture (when that pass changes the page, the page is captured again, so the capture, the live hit tests and the pixel reads agree), the engine hides the roots and backdrops of the consent managers in `crates/browser/src/consent.rs`: OneTrust, Cookiebot, Usercentrics, TrustArc, Didomi, Quantcast Choice, Sourcepoint, Osano, the open-source Cookie Consent library, CookieYes, Complianz, iubenda, Termly, Axeptio, Borlabs Cookie (its box, its floating `#BorlabsCookieWidget` and its `#BorlabsDialogBackdrop`), Klaro, Cookie Notice, Shopify's privacy banner, consentmanager (`#cmpwrapper`, the host of the open shadow root its box renders in, and `#cmpbox`), and Google Funding Choices. Selectors are the vendor's own ids and classes, never a generic word, so a notice a site wrote for itself stays on the page and is scanned. Hiding is one injected `<style id="impeccable-consent-hide">` of `display: none !important` rules (plus an inline `display: none !important` on a matched element whose own inline style outranks the rule); nothing is clicked and no cookie or consent state is set. The scroll lock is undone only where the manager applied it: its own lock classes on `<html>` / `<body>` (Didomi `didomi-popup-open`, Sourcepoint `sp-message-open`) are removed, the `aria-hidden="true"` a manager put on the page behind its dialog is removed from exactly the elements it marked (Borlabs Cookie marks them `data-borlabs-cookie-aria-hidden`; reported in `unlocked` as `aria-hidden [<mark>]`), and an inline `overflow` / `overflow-y: hidden` on `<html>` or `<body>` is removed only while that manager's backdrop was showing the page is not an app shell (an element outside the managers at least half the viewport tall that scrolls itself with `overflow-y: auto` / `scroll`, whose body lock is the site's own), and no modal of the site's own (`dialog[open]`, `[aria-modal="true"]`, `[role="dialog"]`, `[role="alertdialog"]` outside the managers) is showing, since that modal may hold the lock. Every hide pass is best-effort: one that fails hides nothing and does not fail the scan. Every pass, the hit tests, and the evidence screenshot see the page without the banner (a last hide runs before the screenshot). Findings from a scan that hid a showing banner carry `consentHidden: ["<name>", ...]` (after `thirdParty`), and text mode prints the note above. `--no-consent-hiding` turns all of it off. The evidence API (`detect_url_evidence`) leaves the findings untagged, so they replay equal, and records `Evidence.consent`: `{ hidden, matched: { <name>: [selectors] }, unlocked }`. The static (file) engine is unaffected.
- - **Tours and preloaders** (Rust engine, `crates/browser/src/overlays.rs`). Right after the consent hide following the validity gate, the engine looks for a preloader still covering the page: a `position: fixed` layer other than `html` / `body` that covers at least 90% of the viewport, is what `elementFromPoint` returns (or contains it) at the center and at 20% / 80% of each axis (a layer with `pointer-events: none` is made hit-testable for that probe and put back), paints an opaque fill (alpha 0.9 or more) on itself or on a descendant covering as much, has at most 60 visible characters and no `a[href]`, `button`, visible `input`, `select`, `textarea`, `iframe`, `[role=button]`, dialog role, `aria-modal=true`, `dialog` or editable descendant, is not itself a dialog, and whose id or one of its classes names a loader (after trailing wrapper words such as `wrapper`, `overlay`, `screen`, `bg`, its last `-` / `_` word is `preloader`, `preload`, `preloading`, `loader`, `loading`, `pageloader`, `siteloader`, `loadingscreen` or `spinner`). If one is there the engine polls every 250ms for up to 5s for it to go on its own, then hides whatever is left with an inline `display: none !important` and marks it `data-impeccable-hidden="<name>"` (`<name>` is the tag plus the naming id or class, `div#preloader`). Known product tours are hidden by their library's own markup with one injected `<style id="impeccable-overlay-hide">`: driver.js 1.x (`.driver-popover`, `svg.driver-overlay`), whose `driver-active` / `driver-fade` / `driver-simple` body classes (its stylesheet sets `pointer-events: none` under `.driver-active`, which hides the page from hit tests), highlight classes (`driver-active-element`, `driver-no-interaction`) and highlight aria (`aria-controls="driver-popover-content"` with `aria-haspopup` and `aria-expanded`) are removed too. The hide runs at the same points as the consent hide (after the validity gate, after the reveal sweep, after the capture with a recapture when it changed the page, before the screenshot) and is as best-effort. A gate the visitor answers, a site's own dialog, and any layer with controls or more text are left on the page. Findings from a scan that hid any carry `overlaysHidden: [{ "kind": "tour" | "preloader", "name": "<name>" }, ...]` (tours first, after `consentHidden`), and text mode prints the note above. `consentHidden` is unchanged and lists consent managers only. When a preloader is hidden, the scroll lock its page kept with it is undone too: a loader-named class on `<html>` or `<body>` (`is-loading`) is removed, and so is an inline `overflow` / `overflow-y: hidden` on either unless a modal of the site's own is open or an app shell scrolls inside itself (either may hold that lock) (recorded in `unlocked` as `body.is-loading`, `body style overflow`). `--no-overlay-hiding` turns all of it off, the wait included. The evidence API leaves the findings untagged and records `Evidence.overlays`: `{ hidden: [{ kind, name }], matched: { <library>: [selectors] }, unlocked, waitedMs }` (`waitedMs` is 0 when no preloader was covering the page).
+ Consent wall: a page where a known consent manager (next item) is showing (its text counted with the text of open shadow roots under its roots, where Usercentrics renders), hiding it would leave next to nothing (fewer than 20 visible characters outside its roots, and no visible form control (`input` other than hidden, `select`, `textarea`, `button`) and no `img`, `svg`, `video`, `canvas`, `iframe`, `object` or `embed` of 10,000 square pixels or more outside them), and the manager holds at least 100 characters or a frame of 10,000 square pixels or more (a message drawn in an iframe, whose text the page cannot read). For this test, text of the manager's that `body.innerText` does not see (rendered in a shadow root, or in a root appended outside `<body>`) is added to the page's visible-text count too (`consentShadowChars`), so the two counts describe the same text; the challenge checks keep the page's own count. It throws `the page is a consent wall, not the site (consent manager <names>, <n> of <total> visible characters outside it, no control or image outside it). Findings would describe the consent dialog, so none are reported.` A short page under an ordinary banner (a sign-in form, a splash page with a button, an image-first page) is scanned. The probe runs before any banner is hidden, and again in the same evaluation as each later hide pass (after the reveal sweep, right after the capture, and after the `content-hidden-at-rest` scroll probe when it scrolled the page), whenever a manager's root is in the page, with the earlier hide rules switched off and its inline hides lifted for that read (an inline hide the manager has since replaced with its own display, or with the same `display: none !important` written by rewriting its style attribute, stays as the manager set it), so a wall that arrives after load, fills a root that was an empty stub, or arrives during the capture or the scroll probe is refused too (the evidence then carries that later probe). A manager's box is showing when it has a size and paints (`checkVisibility` with opacity and visibility), and is not parked out of sight: a fixed box wholly outside the viewport (unless a transformed, filtered or contained ancestor holds it), a box wholly above or beside the document, or a box an ancestor's overflow clips away. Controls and media outside the roots are counted in the page's open shadow roots at any depth, nested web components included. With `--no-consent-hiding` the gate is off and the page is scanned with its banner, which is what that flag asks for. The probe object (evidence) carries `consent` (the names of the managers showing), `consentChars` (visible characters inside them) and `consentOutside` (visible controls and sizable media outside them, counted up to 20).
+ - **Consent banners** (Rust engine). A consent banner covers copy a visitor reads once they dismiss it: text under it was skipped as covered or scored against the banner, and the banner's own text was scored as the site's. After the validity gate, again after the reveal sweep (so a banner injected after load or on the first scroll is caught before the capture), once more right after the capture (when that pass changes the page, the page is captured again, so the capture, the live hit tests and the pixel reads agree), and after the `content-hidden-at-rest` scroll probe when it scrolled the page (so a banner that scrolling injects is off the page for the pixel pass; the capture already read stands), the engine hides the roots and backdrops of the consent managers in `crates/browser/src/consent.rs`: OneTrust, Cookiebot, Usercentrics, TrustArc, Didomi, Quantcast Choice, Sourcepoint, Osano, the open-source Cookie Consent library, CookieYes, Complianz, iubenda, Termly, Axeptio, Borlabs Cookie (its box, its floating `#BorlabsCookieWidget` and its `#BorlabsDialogBackdrop`), Klaro, Cookie Notice, Shopify's privacy banner, consentmanager (`#cmpwrapper`, the host of the open shadow root its box renders in, and `#cmpbox`), and Google Funding Choices. Selectors are the vendor's own ids and classes, never a generic word, so a notice a site wrote for itself stays on the page and is scanned. Hiding is one injected `<style id="impeccable-consent-hide">` of `display: none !important` rules (plus an inline `display: none !important` on a matched element whose own inline style outranks the rule); nothing is clicked and no cookie or consent state is set. The scroll lock is undone only where the manager applied it: its own lock classes on `<html>` / `<body>` (Didomi `didomi-popup-open`, Sourcepoint `sp-message-open`) are removed, the `aria-hidden="true"` a manager put on the page behind its dialog is removed from exactly the elements it marked (Borlabs Cookie marks them `data-borlabs-cookie-aria-hidden`; reported in `unlocked` as `aria-hidden [<mark>]`), and an inline `overflow` / `overflow-y: hidden` on `<html>` or `<body>` is removed only while that manager's backdrop was showing the page is not an app shell (an element outside the managers at least half the viewport tall that scrolls itself with `overflow-y: auto` / `scroll`, whose body lock is the site's own), and no modal of the site's own (`dialog[open]`, `[aria-modal="true"]`, `[role="dialog"]`, `[role="alertdialog"]` outside the managers) is showing, since that modal may hold the lock. Every hide pass is best-effort: one that fails hides nothing and does not fail the scan. Every pass, the hit tests, and the evidence screenshot see the page without the banner (a last hide runs before the screenshot). Findings from a scan that hid a showing banner carry `consentHidden: ["<name>", ...]` (after `thirdParty`), and text mode prints the note above. `--no-consent-hiding` turns all of it off. The evidence API (`detect_url_evidence`) leaves the findings untagged, so they replay equal, and records `Evidence.consent`: `{ hidden, matched: { <name>: [selectors] }, unlocked }`. The static (file) engine is unaffected.
+ - **Tours and preloaders** (Rust engine, `crates/browser/src/overlays.rs`). Right after the consent hide following the validity gate, the engine looks for a preloader still covering the page: a `position: fixed` layer other than `html` / `body` that covers at least 90% of the viewport, is what `elementFromPoint` returns (or contains it) at the center and at 20% / 80% of each axis (a layer with `pointer-events: none` is made hit-testable for that probe and put back), paints an opaque fill (alpha 0.9 or more) on itself or on a descendant covering as much, has at most 60 visible characters and no `a[href]`, `button`, visible `input`, `select`, `textarea`, `iframe`, `[role=button]`, dialog role, `aria-modal=true`, `dialog` or editable descendant, is not itself a dialog, and whose id or one of its classes names a loader (after trailing wrapper words such as `wrapper`, `overlay`, `screen`, `bg`, its last `-` / `_` word is `preloader`, `preload`, `preloading`, `loader`, `loading`, `pageloader`, `siteloader`, `loadingscreen` or `spinner`). If one is there the engine polls every 250ms for up to 5s for it to go on its own, then hides whatever is left with an inline `display: none !important` and marks it `data-impeccable-hidden="<name>"` (`<name>` is the tag plus the naming id or class, `div#preloader`). Known product tours are hidden by their library's own markup with one injected `<style id="impeccable-overlay-hide">`: driver.js 1.x (`.driver-popover`, `svg.driver-overlay`), whose `driver-active` / `driver-fade` / `driver-simple` body classes (its stylesheet sets `pointer-events: none` under `.driver-active`, which hides the page from hit tests), highlight classes (`driver-active-element`, `driver-no-interaction`) and highlight aria (`aria-controls="driver-popover-content"` with `aria-haspopup` and `aria-expanded`) are removed too. The hide runs at the same points as the consent hide (after the validity gate, after the reveal sweep, after the capture with a recapture when it changed the page, after the scroll probe when it ran, before the screenshot) and is as best-effort. A gate the visitor answers, a site's own dialog, and any layer with controls or more text are left on the page. Findings from a scan that hid any carry `overlaysHidden: [{ "kind": "tour" | "preloader", "name": "<name>" }, ...]` (tours first, after `consentHidden`), and text mode prints the note above. `consentHidden` is unchanged and lists consent managers only. When a preloader is hidden, the scroll lock its page kept with it is undone too: a loader-named class on `<html>` or `<body>` (`is-loading`) is removed, and so is an inline `overflow` / `overflow-y: hidden` on either unless a modal of the site's own is open or an app shell scrolls inside itself (either may hold that lock) (recorded in `unlocked` as `body.is-loading`, `body style overflow`). `--no-overlay-hiding` turns all of it off, the wait included. The evidence API leaves the findings untagged and records `Evidence.overlays`: `{ hidden: [{ kind, name }], matched: { <library>: [selectors] }, unlocked, waitedMs }` (`waitedMs` is 0 when no preloader was covering the page).
- **What the visual pass refuses to read.** The JS reported whatever its sampling produced; the engine says nothing where the reading is not the text's own background. The candidate collector applies the element pass's text gates before a candidate takes one of the `maxCandidates` slots, is sampled, or is scrolled into view: text with no letter and no digit (`◯`, `{ }`, `/`) as well as emoji-only text; a disabled control (`[disabled]`, `[aria-disabled="true"]`); a computed font size under 1px; a `color` at alpha 0.02 or less, or a transparent `-webkit-text-fill-color`, unless the element clips its own background to its text; and an element the painted-at-capture predicate (`crates/core/src/browser/painted.rs`, text gate) says is not painted, such as a tab-strip cell past its clipping edge or a carousel slide parked beside the page. A background image read as a surface has to be under the text: an image drawn `no-repeat` (from the computed `background` shorthand's first layer) whose painted rect, at a `background-size` the capture can place (pixels, percentages, `cover`, or any size once the image's intrinsic size is loaded), covers neither the candidate's text box nor its own box (`body` and `html` are asked only about the text) ends the walk `background image does not cover the text` (`stop`), whether or not the pass could load the file. An icon sprite framing a count and a mark beside a button label are refused this way; a repeating tile and a placement the capture cannot state are read as before. In the stack walk (`impeccable_core::browser::visual`): a translucent surface no longer restarts the walk at its own parent (which re-entered the stack above the node it came from and composited that surface over itself until its alpha read as opaque, and which skipped siblings painted between the surface and that parent) — the walk keeps descending the one `elementsFromPoint` stack, collecting translucent surfaces until an opaque one grounds them, then composites them back in order (topmost surface still names the method, `...+alpha`); a walk that reaches the end of the stack with nothing opaque is unresolved rather than reporting the last translucent color as a surface. A gradient answers analytically only when its stops agree: any stop below 0.95 alpha (a scrim, a glow, a `from-x/10` wash composites differently at every point of the box) or two opaque stops more than 2× apart in contrast make it `gradient stops disagree`, and an `svg` in the stack makes it `<tag> paint`; both end the walk (`stop`) rather than letting the nodes under them answer for the text, so the candidate falls to the screenshot pass. In the screenshot flow: a candidate whose reasons include `background-clip text`, `filter`, or `backdrop filter` is refused before the two screenshots are taken; the verdict is the median over the *glyph cores* (channel delta ≥ 90% of the strongest delta in the box, ≥ 8 of them; when fewer than 8 pixels reach 90%, as on small or thin text, the pixels from 75% up) rather than the tenth percentile over every changed pixel, which antialiased edges drive to 1:1; and the pass reports nothing when the diff is not a glyph over its background — more than 55% of the clip changed (the page repainted), more than a quarter of the changed pixels moved the opposite way from the rest (text mid-animation leaves its old position and its new one in the same diff), most fully painted pixels are not the color the text declares (`preferRenderedForeground` aside, where the painted value *is* the claim), the surface under the glyphs stands 2:1 or further from the surface beside them in the same box (the page paints its own text twice, so hiding one copy leaves the other where the glyphs were), or the median of every measured pixel is more than 3× the verdict (the sample is two populations, not one surface). The snippet shape is unchanged. `median` in it is the median over the same glyph cores the verdict reads, so it prints the verdict's number and never reads below it (it used to be the median over every changed pixel, edges included, which printed verdicts above their own median such as `pixel contrast 3.5:1 median 1.7:1`). The median over every changed pixel still decides the bimodal refusal above, but it is not printed.
- **Viewport edges and overflow.** `body-text-viewport-edge` reports a gutter under 16px, or under 12px when `innerWidth` is 480px or less. A paragraph whose measured text runs past a side of the viewport (the distance rounds below 0) reports no gutter on that side; it still reports a gutter from 0px to the floor on the other side (`(left 8px)`). Those paragraphs, through the same gates plus the Text paint gate and inline ignores, report once per page instead: one `body-text-viewport-edge` finding attributed to the page (`selector` `body`, in `pageLevel`) on the side the furthest text reaches. The message follows what the page does. It reads `text runs past the <side> edge of the <vw>px viewport and is cut off: <name> reaches <d>px past it, with text in <n> block(s)` when the text is cut off: the viewport clips x overflow (the root's `overflow-x`, or body's when the root's is `visible`, at `hidden` or `clip`), the side is not the one the page scrolls to (right, or left under `direction: rtl`), the root's recorded `scrollWidth` does not exceed its `clientWidth` by more than 1px, or for every paragraph on that side a box at `overflow-x: hidden` or `clip` (the paragraph or an ancestor below the body, with its own edge on that side inside the viewport) is passed by the text. `<name>` is then the box reaching furthest among the paragraphs and their ancestors. Otherwise it reads `page scrolls sideways at <vw>px: <name> reaches <d>px past the <side> edge, and text in <n> block(s) runs past it`, where `<name>` is the box reaching furthest past that side among those no ancestor below the root clips or scrolls on x and not `position: fixed`, and no further than the page scrolls (ties go to the outer box). When the engine cannot tell (nothing it can see clips the text and the root recorded no `scrollWidth`) the sideways wording stands and `<name>` is the box reaching furthest among the paragraphs and their ancestors. In both wordings the paragraph itself is named when its text reaches further than any such box. `<name>` is the element's `class_selector`, except that a `div` with no class is named `div#<id>`, else `div in <tag>#<id>` or `div in <tag>.<class>` (at most three classes) after its nearest ancestor below the body with an id or a class, else `div ("<text>")` with up to 40 characters of its text, cut at a word and ended with `…` when cut, double quotes in the text written as `'`. `text-overflow` reports a spill only when it does harm: a box at `overflow-x: hidden` or `clip` (the element itself or an ancestor below the body, with area) is passed by the spill's reach, the spill reaches within a quarter em of the viewport's side or past it, or the spilled part comes within a quarter em of another element's text or painted box on the element's lines (not an ancestor or descendant, not a box that holds the element's whole box, and not a decoration layer: an absolutely or fixed positioned box with no text, other than a replaced element or an `svg`, that is 2px thick or less or paints only a plain fill, with no background image or border, at alpha times opacity under 0.25). The reach is the painted extent, or the scroll extent where that is taken as read; text that runs past its box into free space reports nothing.
- **Round 7 recall and gates** (corpus run 28). `line-length` and `body-text-viewport-edge` (its element and page-level forms) also measure prose written straight into a generic block: a `div`, `section`, `article`, `aside` or `main` laid out as `block` or `flow-root`, with more than 10 characters of its own text, only phrasing inside it, not set `white-space: pre*`, and outside any link, button, label, summary, select, textarea, button-, link-, tab-, menuitem- or option-role element and editable field; it is measured on its text runs only (where those cannot be measured it is not taken for a paragraph), and the edge snippet names it (`<div> with 228-char body ...`). The label collectors read the element that holds a label's text: its own text, else the one child whose text is not empty, at most three levels down, so a chip with an icon beside its text span is read through the span; `hero-eyebrow-chip` reads its sibling that way too, and its tracked-caps floor is 1.6px or 0.08em of the label's size; under 1.6px a label that is or holds a `time` element, or that names a year (1900 to 2099 as a word), is a dated meta line and not tracked caps (the recorded JS vectors pin the fixed floor alone). `kicker-above-heading` hands a label over a 48px-or-larger h1 to the hero rule at 1.6px, or, when the label is the h1's own previous sibling at 14px or less, at 0.08em where `hero-eyebrow-chip` reports that label (it does not read small-caps as capitals and passes over a dated line, so such a label stays a kicker; the static engine: at 14px or less). A card-context ancestor (`article`, `li`, `a`, `button`, ...) more than two viewports tall holds the page and is not a card for the kicker and numbered-label collectors. `icon-tile-stack` anchors on a card title set on a `div` or `span` too: laid out as a block, with no element children, 2 to 80 characters of its own text, weight 600 or more at 16px or more, outside any heading, link, button or label; it reads an `oklab()` or other modern tile fill. `tiny-text` skips a label typed in capitals (all its letters capitals, at most 40 letters, one line) and a run in a monospace face with `white-space: pre*`. `wide-tracking` counts a caps label's letters, not its characters, toward its 40-letter gate, and skips a one-line link or button label of at most 40 letters. The element contrast pass scores a box under 10px tall when it holds a line of its own text at 8px or more and is at least 0.9 of the font size tall. `ai-color-palette`'s gradient form skips a box whose gradient, sampled at nine points over the box from its computed size and position, shows one colour (every sample within 12 levels on each channel); an element reports the rule once: the computed gradient form stands for the utility-class gradient form, the computed purple-heading form for the class form (`text-purple-600 on heading`), and `gradient-text` on the element for both gradient forms. `gradient-text` skips a ramp whose strongest stop, times the element's own opacity, is under 0.15, and its stylesheet form does not stand when every element computing a clipped gradient is unpainted or under that floor. `gpt-thin-border-wide-shadow` reads, under one gradient ancestor with no picture, each of its stops composited over the fills below: a halo that shows over at most half of them does not count. `dark-glow`'s surface lift counts only layers carrying at least half the strength floor (1.5px of light), and its stylesheet form with no selector does not stand when an element's computed shadow carries the declaration: the element form read that element.
diff --git a/tests/fixtures/consent/after-scroll-probe-banner.html b/tests/fixtures/consent/after-scroll-probe-banner.html
new file mode 100644
index 000000000..17c164289
--- /dev/null
+++ b/tests/fixtures/consent/after-scroll-probe-banner.html
@@ -0,0 +1,54 @@
+<!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 banner the scroll probe brings in</title>
+ <style>
+ /* A page with a section whose opacity follows the scroll, so the scan
+ scrolls to it after the capture to see it show, and a OneTrust bar
+ the page injects the second time it is scrolled back to the top: the
+ reveal sweep's return is the first, the scroll probe's the second.
+ The bar arrives after every pre-capture hide pass, so the scan hides
+ it once more after probing. 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; }
+ p { width: 640px; }
+ .spacer { height: 1400px; }
+ .scrub { opacity: 0; height: 600px; }
+ #onetrust-banner-sdk { position: fixed; left: 0; right: 0; bottom: 0; background: #fff; z-index: 1000; padding: 20px; border-top: 1px solid #ccc; }
+ </style>
+</head>
+<body>
+ <h1>Reveals that follow the scroll</h1>
+ <p>The section below sits at opacity 0 while the page is at the top and shows once a visitor scrolls to it.</p>
+ <div class="spacer"></div>
+ <section class="scrub" id="scrubbed-section">
+ <h2>Automated material movement</h2>
+ <p>Autonomous vehicles keep every machine supplied. Raw materials and finished parts flow
+ between stations without a forklift queue, and the floor plan adapts as the order book
+ changes from one week to the next, so capacity follows demand instead of lagging it.</p>
+ <p>Operators see where every pallet is, what it carries and where it goes next.</p>
+ </section>
+ <div class="spacer"></div>
+ <script>
+ const clamp = (v) => Math.max(0, Math.min(1, v));
+ const scrub = document.getElementById('scrubbed-section');
+ let lastY = 0;
+ let returns = 0;
+ const inject = () => {
+ const sdk = document.createElement('div');
+ sdk.id = 'onetrust-consent-sdk';
+ sdk.innerHTML = '<div id="onetrust-banner-sdk"><p>By clicking "Accept All Cookies", you agree to the storing of cookies on your device to enhance site navigation and analyze site usage.</p><button type="button">Accept All Cookies</button></div>';
+ document.body.appendChild(sdk);
+ };
+ window.addEventListener('scroll', () => {
+ const vh = window.innerHeight;
+ const r = scrub.getBoundingClientRect();
+ scrub.style.opacity = String(clamp((vh * 0.8 - r.top) / (vh * 0.4)));
+ if (window.scrollY === 0 && lastY > 0 && ++returns === 2) inject();
+ lastY = window.scrollY;
+ }, { passive: true });
+ </script>
+</body>
+</html>
diff --git a/tests/fixtures/consent/held-fixed-banner.html b/tests/fixtures/consent/held-fixed-banner.html
new file mode 100644
index 000000000..92a869044
--- /dev/null
+++ b/tests/fixtures/consent/held-fixed-banner.html
@@ -0,0 +1,29 @@
+<!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 fixed banner a transformed ancestor holds</title>
+ <style>
+ /* A OneTrust bar set position: fixed inside a transformed wrapper far
+ below the first viewport. The transform makes the wrapper the bar's
+ containing block, so the bar scrolls with the page and a visitor
+ reaches it: it is showing, not parked past the viewport, and the scan
+ hides it. 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; }
+ .holder { position: absolute; top: 1500px; left: 0; right: 0; height: 200px; transform: translateZ(0); }
+ #onetrust-banner-sdk { position: fixed; left: 0; right: 0; top: 0; padding: 20px; background: #fff; border-top: 1px solid #ccc; }
+ </style>
+</head>
+<body>
+ <h1>Opening hours</h1>
+ <p>The studio is open Tuesday to Saturday from ten until six, and by appointment on Mondays.</p>
+ <div class="holder">
+ <div id="onetrust-consent-sdk">
+ <div id="onetrust-banner-sdk">
+ <p>By clicking "Accept All Cookies", you agree to the storing of cookies on your device to enhance site navigation and analyze site usage.</p>
+ </div>
+ </div>
+ </div>
+</body>
+</html>
diff --git a/tests/fixtures/consent/late-closed-attr-banner.html b/tests/fixtures/consent/late-closed-attr-banner.html
new file mode 100644
index 000000000..8551cd1ca
--- /dev/null
+++ b/tests/fixtures/consent/late-closed-attr-banner.html
@@ -0,0 +1,32 @@
+<!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 late banner that closes itself with !important</title>
+ <style>
+ /* late-closed-banner.html, except the manager closes its dialog by
+ rewriting its root's style attribute to display: none !important,
+ the same declaration the first hide pass stamped on it. The late wall
+ check leaves that closed root closed, and the page is scanned.
+ Pinned by crates/browser/tests/consent_hiding.rs. */
+ body { font: 16px/1.5 system-ui, sans-serif; margin: 0; min-height: 3000px; background: #f3f4f6; }
+ </style>
+</head>
+<body>
+ <div id="usercentrics-root" style="display: block !important"></div>
+ <script>
+ const root = document.getElementById('usercentrics-root');
+ window.addEventListener('scroll', () => {
+ if (!root.shadowRoot) {
+ root.attachShadow({ mode: 'open' }).innerHTML =
+ '<style>.box { position: fixed; top: 80px; left: 50%; width: 640px; margin-left: -320px; padding: 32px; background: #fff; }</style>'
+ + '<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></div>';
+ } else if (window.scrollY > 600) {
+ root.setAttribute('style', 'display:none!important');
+ }
+ }, { passive: true });
+ </script>
+</body>
+</html>
diff --git a/tests/fixtures/consent/parked-banner-page.html b/tests/fixtures/consent/parked-banner-page.html
new file mode 100644
index 000000000..6d71031b3
--- /dev/null
+++ b/tests/fixtures/consent/parked-banner-page.html
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <title>Consent hiding: closed dialogs parked offscreen and clipped away</title>
+ <style>
+ /* A page with a few words of its own and two closed consent dialogs
+ whose text outweighs it: a OneTrust preference center a fixed layer
+ parks far above the viewport, and a TrustArc bar inside a fixed
+ wrapper collapsed to no height, which clips it away. Neither paints,
+ so neither is showing, and the page is scanned rather than refused as
+ a consent wall. Pinned by crates/browser/tests/consent_hiding.rs. */
+ body { font: 16px/1.5 system-ui, sans-serif; margin: 0; padding: 40px; background: #fff; color: #111; }
+ #onetrust-pc-sdk { position: fixed; top: -3000px; left: 50%; width: 640px; margin-left: -320px; padding: 32px; background: #fff; }
+ .bar-wrap { position: fixed; left: 0; right: 0; bottom: 0; height: 0; overflow: hidden; }
+ #consent_blackbar { padding: 24px; background: #fff; }
+ </style>
+</head>
+<body>
+ <h1>Hours</h1>
+ <div id="onetrust-consent-sdk">
+ <div id="onetrust-pc-sdk" role="dialog" aria-label="Privacy preferences">
+ <h2>Your privacy choices</h2>
+ <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, to measure the performance of content and advertising, and to develop and improve our products.</p>
+ </div>
+ </div>
+ <div class="bar-wrap">
+ <div id="consent_blackbar">
+ <p>This site uses cookies and related technologies for site operation, analytics and third-party advertising. You may choose to consent to our use of these technologies, or manage your own preferences.</p>
+ </div>
+ </div>
+</body>
+</html>
diff --git a/tests/fixtures/consent/shadow-nested-form-page.html b/tests/fixtures/consent/shadow-nested-form-page.html
new file mode 100644
index 000000000..4edb9ef25
--- /dev/null
+++ b/tests/fixtures/consent/shadow-nested-form-page.html
@@ -0,0 +1,32 @@
+<!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 nested web-component sign-in form under a banner</title>
+ <style>
+ /* shadow-form-page.html with the form one component deeper: an app
+ shell's open shadow root holds a login component, whose own shadow
+ root holds the form. The form is still the page's content outside
+ the manager, so the page is scanned, not refused as a consent wall.
+ 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>
+</head>
+<body>
+ <x-app></x-app>
+ <div id="onetrust-consent-sdk">
+ <div id="onetrust-pc-sdk" role="dialog" aria-label="Privacy preferences">
+ <h2>Your privacy choices</h2>
+ <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>
+ </div>
+ <script>
+ const app = document.querySelector('x-app').attachShadow({ mode: 'open' });
+ app.innerHTML = '<div style="padding:24px"><x-login></x-login></div>';
+ const login = app.querySelector('x-login').attachShadow({ mode: 'open' });
+ login.innerHTML = '<form style="display:block"><label><input type="email" name="email"></label> <button type="submit"></button></form>';
+ </script>
+</body>
+</html>