""" Browser-side DOM walkers for Web-Component CMPs and OEM design-systems. Centralizes the JavaScript snippets used by banner_text_checker.py so the checker file stays under the 500-LOC cap. Each function returns a JS string that Playwright passes to `page.evaluate()`. Two walkers: * SHADOW_BANNER_WALKER_JS — pierces shadow DOM (Mercedes cmm-cookie-banner, BMW cookie-consent-banner, etc.) and extracts banner text + label-based legal links (P63 — recognizes wb7-link/role=link/button, not just , since OEM design-systems wrap navigation). * FOOTER_LABELS_WALKER_JS — collects unique footer link labels from any candidate footer root (footer, [role=contentinfo], wb7-footer, ...) with a bottom-25%-of-viewport fallback (P64). """ from __future__ import annotations SHADOW_BANNER_WALKER_JS = """() => { const LEGAL_KW = { impressum: ['impressum','imprint','legal notice','mentions legales','colophon'], dse: ['datenschutz','privacy','dsgvo','data protection','politique de confidentialite'], }; function isLegalLabel(txt) { const t = (txt||'').toLowerCase(); if (!t || t.length > 60) return null; for (const k of LEGAL_KW.impressum) if (t.includes(k)) return 'impressum'; for (const k of LEGAL_KW.dse) if (t.includes(k)) return 'dse'; return null; } // P76: EXTENDED — scan ANY clickable element by label, not just // or named web-components. Mercedes uses small secondary // buttons below the main 3 actions: "Datenschutzerklaerung" + "Impressum" // as /