Skip to content

Fix: Process all disallowed elements instead of stopping after first#46

Merged
webworkerJoshua merged 1 commit intowebworkerJoshua:masterfrom
gebeer:fix/iframe-consent-multiple-elements
Aug 15, 2025
Merged

Fix: Process all disallowed elements instead of stopping after first#46
webworkerJoshua merged 1 commit intowebworkerJoshua:masterfrom
gebeer:fix/iframe-consent-multiple-elements

Conversation

@gebeer
Copy link
Contributor

@gebeer gebeer commented Aug 14, 2025

Summary

  • Fix bug in checkElementsWithRequiredConsent() where early return caused loop to exit after processing first disallowed element
  • Change return to continue to ensure all blocked elements get consent messages
  • Resolves issue where only first element with denied consent category would display ask-consent message

Problem

When multiple elements on a page require the same denied consent category (e.g., iframe + script both needing external_media), only the first element displays a consent message. Subsequent elements are silently blocked without any user-facing consent request.

Root Cause

Bug in checkElementsWithRequiredConsent() method (line 435)

// Buggy code
if (!allowed) {
  this.updateDisallowedElement(el);
  return; // ← Exits entire loop
}

Solution

// Fixed code  
if (!allowed) {
  this.updateDisallowedElement(el);
  continue; // ← Process next element
}

Test Results ✅

  1. Page Load: Both iframe and script are properly blocked
  2. Consent Message: Displayed adjacent to iframe with correct category text
  3. Button Click: Iframe loads, consent message removed, localStorage updated
  4. Script Execution: Associated scripts load and execute properly

Related Issue

Fixes #45

🤖 Generated with Claude Code

- Fix bug in checkElementsWithRequiredConsent() where return statement
  caused loop to exit after processing first disallowed element
- Change return to continue to ensure all blocked elements get consent messages
- Resolves issue where only first element with denied consent category
  would display ask-consent message, subsequent elements were ignored

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@artfulrobot
Copy link
Contributor

Looks good to me. (I suspect the author forgot it was a for () loop not a [].forEach() style loop!)

@webworkerJoshua webworkerJoshua merged commit 4a36095 into webworkerJoshua:master Aug 15, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Consent messages only show for first blocked element when multiple elements have same denied category

3 participants