diff --git a/consent-tester/services/consent_history.py b/consent-tester/services/consent_history.py index ca30914f..49327ca5 100644 --- a/consent-tester/services/consent_history.py +++ b/consent-tester/services/consent_history.py @@ -53,9 +53,11 @@ def _is_versioned(provider: str, stored_value: Optional[str]) -> bool: return any(t in low for t in ("version", "consents", "timestamp", "consentid")) -async def detect_consent_history(page: Any) -> dict: +async def detect_consent_history(page: Any, banner_provider: str = "") -> dict: """Liest Storage/Cookies + DOM und liefert: - {provider, stored, versioned_consent, history_capable, withdraw_ui}.""" + {provider, stored, versioned_consent, history_capable, withdraw_ui}. + `banner_provider` = bereits aus dem Banner-DOM erkanntes CMP — wird als + Fallback genutzt, da Storage-Keys in Phase A (vor Consent) oft noch fehlen.""" keys: list[str] = [] try: keys = await page.evaluate("() => Object.keys(window.localStorage || {})") @@ -67,7 +69,9 @@ async def detect_consent_history(page: Any) -> dict: except Exception: cookie_names = [] - provider = classify_provider(list(keys) + cookie_names) + # Provider zuerst aus Storage/Cookies, sonst aus dem erkannten Banner-CMP. + provider = (classify_provider(list(keys) + cookie_names) + or classify_provider([banner_provider or ""])) stored_value = None if provider == "Borlabs": diff --git a/consent-tester/services/consent_scanner.py b/consent-tester/services/consent_scanner.py index ee46920e..f6c0f920 100644 --- a/consent-tester/services/consent_scanner.py +++ b/consent-tester/services/consent_scanner.py @@ -280,7 +280,8 @@ async def run_consent_test( # #62: Consent-Historie/Widerruf (Borlabs-Stil) erkennen. try: from services.consent_history import detect_consent_history - result.consent_history = await detect_consent_history(page_a) + result.consent_history = await detect_consent_history( + page_a, result.banner_provider) except Exception as _che: logger.warning("consent-history detection failed: %s", _che)