Script Blocking

Learn how Cookient blocks third-party scripts until consent is given, which scripts to configure, and which ones should never be blocked.

Overview

Script blocking prevents third-party scripts from loading until the user gives consent. This is a core GDPR requirement – scripts that set cookies or track users must not run before explicit consent is obtained.

What Gets Blocked

  • Analytics scripts – Google Analytics, Hotjar, Clarity, Plausible
  • Marketing scripts – Facebook Pixel, Google Ads, LinkedIn Insight
  • Personalization scripts – Intercom, Drift, HubSpot chat
  • Embedded content – YouTube iframes, Google Maps, social media embeds

Cookient uses a MutationObserver to intercept scripts in real-time as they're added to the DOM. This technique blocks scripts before they can execute, ensuring no tracking happens without consent.

How It Works

The script blocking mechanism works in four stages: interception, blocking, storage, and restoration.

  1. 1

    Script Interception

    A MutationObserver watches the DOM for any new <script> tags being added. When a script matches a blocked URL pattern, it's intercepted before execution.

  2. 2

    Blocking

    The script's type attribute is changed to text/plain, which prevents the browser from executing it. The original source URL is preserved.

  3. 3

    Storage

    The original src is stored in a data-cookient-src attribute so it can be restored later if consent is given.

  4. 4

    Restoration

    When the user grants consent for a category, blocked scripts in that category are restored by creating a new script element with the original source.

Simplified Code Example

// Blocking a script
script.type = "text/plain";
script.setAttribute("data-cookient-src", script.src);
script.removeAttribute("src");

// Restoring after consent
const newScript = document.createElement("script");
newScript.src = originalSrc;
newScript.type = "text/javascript";
document.head.appendChild(newScript);
i
Firefox Enhancement
Firefox supports the native beforescriptexecute event, which Cookient uses for even more reliable script blocking on that browser.

Managing Scripts

After running a cookie scan, you can manage which scripts are blocked and their categories from your dashboard.

Viewing Detected Scripts

  1. Navigate to Cookie Management in your dashboard
  2. Select your domain from the dropdown
  3. Click the Scripts tab
  4. View all scripts detected during the scan

Configuring a Script

For each script, you can configure:

  • Category – Which consent category controls this script
  • Blocked status – Whether the script requires consent

When Changes Take Effect

Script configuration changes are cached for performance. Changes take effect:

  • Within 24 hours – Normal cache expiration
  • Immediately – After running a new scan
*
Run a New Scan
To see changes immediately, run a new cookie scan after updating script settings. This refreshes the configuration served to visitors.

Script Categories

Each script is assigned to a consent category. The category determines when the script is allowed to load based on user consent.

CategoryIDBlocked by DefaultExamples
FunctionalfNojQuery, Stripe, reCAPTCHA
AnalyticsaYesGoogle Analytics, Hotjar, Clarity
MarketingmYesFacebook Pixel, Google Ads, LinkedIn
PersonalizationpYesIntercom, Drift, HubSpot
SecuritysNohCaptcha, Cloudflare Turnstile
Uncategorized-YesUnknown third-party scripts

Functional and Security scripts are never blocked because they're essential for your website to function properly. All other categories require user consent before loading.

Essential Scripts

!
Critical: Do Not Block These Scripts
Blocking essential scripts will break your website. If your site looks broken or features stop working after installing Cookient, check that these scripts are NOT marked as blocked.

Some scripts are essential for your website to function. These should always be set to Functional category and never blocked, regardless of consent.

TypeExamplesIf Blocked
CSS FrameworksTailwind CDN, Bootstrap, BulmaSite appears unstyled
JS LibrariesjQuery, React CDN, Vue CDNFeatures stop working
CDNscdnjs, jsDelivr, UNPKGResources fail to load
Payment ProcessorsStripe.js, PayPal SDK, SquareCheckout broken
Security/CaptchareCAPTCHA, hCaptcha, TurnstileForms vulnerable to bots
Font ServicesGoogle Fonts, Adobe FontsFallback fonts used

Cookient's Automatic Protection

Cookient automatically categorizes known essential scripts:

  • Common CDNs (cdnjs, jsDelivr, UNPKG) are marked as Functional
  • Payment processors (Stripe, PayPal) are marked as Functional
  • Security scripts (reCAPTCHA, hCaptcha) are marked as Security

How to Fix a Broken Site

If your site looks broken after Cookient installation:

  1. Open browser Developer Tools → Network tab
  2. Reload the page and look for failed CSS/JS requests
  3. Go to your Cookient dashboard → Cookie ManagementScripts
  4. Find the blocked script and change its category to Functional
  5. Run a new scan to apply changes immediately

Troubleshooting

Site appears unstyled or broken

Cause: CSS framework or JavaScript library is being blocked.

Solution:

  1. Open Developer Tools → Network tab
  2. Look for blocked or failed CSS/JS files
  3. In Cookient dashboard, find the script under Scripts tab
  4. Change category to Functional or uncheck "Blocked"
  5. Run a new scan

Feature stopped working (form, slider, etc.)

Cause: A required JavaScript library is blocked.

Solution:

  1. Open Developer Tools → Console tab
  2. Look for JavaScript errors mentioning undefined functions
  3. Identify which library provides that function
  4. Set that script's category to Functional

Checkout or payment not working

Cause: Payment processor script (Stripe, PayPal) is blocked.

Solution:

  1. Search for "stripe", "paypal", or your payment provider in Scripts tab
  2. Ensure category is set to Functional
  3. Ensure "Blocked" checkbox is unchecked

Payment scripts should never require consent – they're essential for transactions.

Script is blocked even though it shouldn't be

Cause: Script is uncategorized or miscategorized.

Solution:

  1. Go to Cookie ManagementScripts
  2. Find the script by URL or name
  3. Set correct category (Functional for essential scripts)
  4. Uncheck "Blocked" if it should always load

Changes not taking effect

Cause: Configuration is cached.

Solution:

  1. Run a new cookie scan to force cache refresh
  2. Clear your browser cache and cookies
  3. Wait up to 24 hours for CDN cache to expire