Dev.to WebDev πŸ›  Dev πŸ‘ 0 πŸ“– 2 min read

How to Test California Sec-GPC: 1 (Global Privacy Control) with Playwright HAR in 20 Lines of Python

If you test Global Privacy Control (GPC) using curl -H "Sec-GPC: 1" or Playwright extra_http_headers alone, you will miss most real-world CMP failures. Why? Most client-side Consent Management Platforms (Osano, OneTrust

If you test Global Privacy Control (GPC) using curl -H "Sec-GPC: 1" or Playwright extra_http_headers alone, you will miss most real-world CMP failures.

Why? Most client-side Consent Management Platforms (Osano, OneTrust, CookieYes, Complianz, Shopify Customer Privacy) run in the browser and check navigator.globalPrivacyControl === true in JavaScript β€” they never inspect the inbound HTTP request header.

To reproduce what a real GPC-enabled browser (Firefox, Brave, DuckDuckGo, or Privacy Badger) sends under California CCPA/CPRA rules, you must spoof both the HTTP header and the DOM property, then capture a standard Chrome DevTools .har file.

The 20-Line Python Playwright GPC + HAR Harness

from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch(headless=True)
    context = browser.new_context(
        record_har_path="gpc.har",
        record_har_content="omit",
        extra_http_headers={"Sec-GPC": "1", "DNT": "1"},
    )
    context.add_init_script(
        "Object.defineProperty(navigator, 'globalPrivacyControl', { get: () => true });"
    )
    page = context.new_page()
    page.goto("https://example.com", wait_until="networkidle")
    page.wait_for_timeout(3000)
    context.close()  # flushes gpc.har to disk
    browser.close()

What to Check Inside gpc.har

Parse log.entries[].request.url in Python and diff it against a baseline Cold Load .har:

  • facebook.com/tr (Meta Pixel)
  • analytics.tiktok.com (TikTok Pixel)
  • clarity.ms / hotjar.com / fullstory.com (Session replay)
  • google-analytics.com/g/collect (GA4 without Consent Mode gcs=G100 / denied)

Empirical 2026 Result: 59.7% Ignored Sec-GPC: 1

When we ran this exact Playwright harness across 72 live US clinic & medspa websites (all anonymized), 59.7% (43/72) ignored Sec-GPC: 1 and kept firing ad or session-replay pixels β€” even when the site displayed a cookie banner.

Common root causes we observed:

  1. gtm.js placed earlier in <head> than the CMP script, causing tags to fire before GPC evaluation.
  2. WordPress PixelYourSite hardcoding ad_storage and analytics_storage to granted inside var pysOptions.
  3. GTM tags left on "Not set" in Consent Overview.

Open-Source Repo & 30-Second Hosted Runner

(Technical browser observation only; not legal advice.)

πŸ“° Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.