Skip to content

Headless Selenium checker that verifies presence of required cookies (e.g. OneTrust), GTM tags and scripts patterns in a page's source

Notifications You must be signed in to change notification settings

pe9as0/headselcheck

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

4 Commits
ย 
ย 
ย 
ย 

Repository files navigation

README ๐Ÿ“„

Cookie & Tag Presence Checker (Selenium, headless) A small Python utility that loads a web page in headless Chromium (Selenium) and verifies:

  • required cookies (e.g., OptanonConsent, OptanonAlertBoxClosed),
  • OneTrust patterns in page source (e.g., OneTrust, cdn.cookielaw.org, otSDKStub.js),
  • Google Tag Manager patterns (e.g., googletagmanager.com/gtm.js, GTM-, SiteLocalContainer).

Ideal for quick compliance checks and basic instrumentation validation.

What it checks โœ…

Cookies: presence and values for given cookie names.

Page source: substring pattern matches for OneTrust & GTM.

Requirements ๐Ÿงฉ

Python 3.x

Chromium / Chrome + matching chromedriver

Packages: selenium, webdriver-manager (optional)

Install (example): pip install selenium webdriver-manager

โ„น๏ธ Script default path to chromedriver: /usr/bin/chromedriver.

Usage ๐Ÿš€

python3 selescan.py <url> Example: python3 selescan.py https://example.com Output (stdout) will list:

  • found/missing cookies (OptanonConsent, OptanonAlertBoxClosed),
  • found/missing OneTrust patterns,
  • found/missing GTM patterns.

Config (quick edit) โš™๏ธ

Cookie names to verify: edit the list in check_cookies(...) call. Patterns: edit ONETRUST_PATTERNS and GTM_PATTERNS.

Notes / Good practices ๐Ÿ”’

Headless mode is enabled by default. The script currently waits a fixed time.sleep(4) for page load; for SPAs you may want to replace it with Selenium explicit waits (e.g., WebDriverWait on a known selector) or increase the delay. If the site sets cookies after consent or async, consider:

  • waiting for the CMP frame to load,
  • clicking โ€œAcceptโ€ via Selenium before reading cookies,
  • reโ€‘reading cookies after actions.

Possible improvements (optional) ๐Ÿ’ก

Add CLI flags: --cookies, --patterns-file, --wait-seconds, --headful.

Support regex patterns (not only substring).

Structured JSON output (--json) for CI pipelines.

Exit codes (e.g., nonโ€‘zero if any required item is missing).

Add webdriver-manager path usage:

service = Service(ChromeDriverManager().install())

About

Headless Selenium checker that verifies presence of required cookies (e.g. OneTrust), GTM tags and scripts patterns in a page's source

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages