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 Modegcs=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:
-
gtm.jsplaced earlier in<head>than the CMP script, causing tags to fire before GPC evaluation. - WordPress
PixelYourSitehardcodingad_storageandanalytics_storagetograntedinsidevar pysOptions. - GTM tags left on
"Not set"in Consent Overview.
Open-Source Repo & 30-Second Hosted Runner
- Open-source Playwright HAR benchmark script: pixel-cmp-ada-benchmark-2026 on GitHub
- Zero-login 30-second live browser scanner (tests Cold Load,
Sec-GPC: 1, and Reject All + Reload; optional $39 one-time raw.har+ PDF report): TagProof Live Scanner
(Technical browser observation only; not legal advice.)
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.