fix(consent-history): banner_provider als Fallback fürs CMP (#62)

Storage-Keys fehlen in Phase A (vor Consent) oft → provider blieb leer. Jetzt
fällt detect_consent_history auf den bereits aus dem Banner-DOM erkannten
banner_provider zurück → korrekter Anbieter + history_capable auch ohne
Storage-Eintrag.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Benjamin Admin
2026-06-13 17:03:44 +02:00
parent 48709bc595
commit 6f0416a22d
2 changed files with 9 additions and 4 deletions
+7 -3
View File
@@ -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":
+2 -1
View File
@@ -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)