Skip to content

Admin watchdog notice when an ad blocker blocks cookie-policy.js / cookies.js#172

Merged
fabiodalez-dev merged 3 commits into
mainfrom
fix/admin-blocked-script-watchdog
Jul 2, 2026
Merged

Admin watchdog notice when an ad blocker blocks cookie-policy.js / cookies.js#172
fabiodalez-dev merged 3 commits into
mainfrom
fix/admin-blocked-script-watchdog

Conversation

@fabiodalez-dev

@fabiodalez-dev fabiodalez-dev commented Jul 2, 2026

Copy link
Copy Markdown
Owner

Summary

Adds an admin-side watchdog notice for when a visitor's ad blocker (or a privacy extension) blocks the plugin's own front-end assets — cookie-policy.js / cookies.js. When those scripts are blocked, the cookie policy table and the cookie-list widget silently fail to render; this surfaces a clear admin notice so the operator understands the cause instead of chasing a phantom "broken banner" bug.

Notes

  • Admin-only notice; no change to front-end consent/blocking behaviour.

Summary by CodeRabbit

  • Nuove funzionalità

    • Aggiunti avvisi automatici nelle pagine di amministrazione per segnalare quando uno script non si carica correttamente.
    • Gli avvisi includono un messaggio accessibile e si aggiornano in modo dinamico.
  • Bug Fixes

    • Migliorato il rilevamento dei blocchi causati da ad blocker o protezioni privacy.
    • Se lo script viene caricato correttamente, l’avviso resta nascosto o si chiude automaticamente.

…s/cookies.js

The Cookie Policy and Cookies admin pages are driven by per-page scripts whose
filenames contain "cookie" (cookie-policy.js / cookies.js). Ad blockers and
browser privacy shields (e.g. Brave Shield) match those names and block the
file, leaving the page silently inert — Save/Preview and the buttons do nothing.
The form already refuses the native submit (no blank-page data loss, 1.20.0),
but there was no feedback, so the only symptom was "the button does not work"
(support topic: Cookie Policy saving issue).

Each page script now sets a window.faz*Booted flag the instant it runs, and each
view renders a hidden, server-translated 'notice notice-error' plus a tiny
INLINE watchdog that reveals it if the flag is still unset 2.5s after load.
Inline first-party script is not blocked the way the external .js file is, so the
actionable message always reaches the user. Filenames stay descriptive on
purpose — renaming is whack-a-mole against filter lists and costs readability.

E2E: tests/e2e/specs/admin-blocked-script-watchdog.spec.ts (4).
Fix groups (committed):
- [FG-1] F001, F002, F003, F006, F007, F010 — admin/views/cookie-policy.php, admin/views/cookies.php, admin/class-admin.php: verified

Post-fix review: 1/1 groups verified complete; 0 partial; 0 reverted.

Findings addressed (from /adamsreview code review):
- F001/F002: replace the blind 2500ms watchdog timer with window-load-keyed
  detection plus hide-on-boot recovery, so a slow (non-blocked) footer script
  no longer triggers a false "ad blocker" notice and the notice clears if the
  script later loads.
- F006/F007: move the watchdog inline script out of the view templates into
  wp_add_inline_script for the faz-page-cookie-policy / faz-page-cookies handles
  in class-admin.php, mirroring admin/views/languages.php (Plugin-Check clean).
- F003/F010: announce the blocked-script notice via an aria-live assertive
  region populated on reveal, instead of role="alert" on a display:none element.

E2E tests/e2e/specs/admin-blocked-script-watchdog.spec.ts: 4/4 green.
@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2e8b6218-ebbb-4938-8b1d-6bc6172297b9

📥 Commits

Reviewing files that changed from the base of the PR and between f25d1bb and 9b5b631.

📒 Files selected for processing (6)
  • admin/assets/js/pages/cookie-policy.js
  • admin/assets/js/pages/cookies.js
  • admin/class-admin.php
  • admin/views/cookie-policy.php
  • admin/views/cookies.php
  • tests/e2e/specs/admin-blocked-script-watchdog.spec.ts

Walkthrough

La PR aggiunge un meccanismo watchdog per rilevare script admin bloccati (ad-blocker/privacy shield). Gli script cookie-policy.js e cookies.js impostano flag globali di boot; class-admin.php inietta uno script inline che controlla i flag e mostra/nasconde notice nelle relative view PHP; aggiunti test e2e Playwright.

Changes

Watchdog script bloccato

Layer / File(s) Summary
Flag di boot negli script pagina
admin/assets/js/pages/cookie-policy.js, admin/assets/js/pages/cookies.js
Impostano rispettivamente window.fazCpBooted e window.fazCookiesBooted a true all'avvio dello script.
Configurazione e script inline watchdog
admin/class-admin.php
Definisce la mappatura view→flag/notice per cookie-policy e cookies e genera uno script inline che, dopo il load, controlla il flag e mostra o nasconde la notice popolando l'area aria-live.
Markup notice server-rendered
admin/views/cookie-policy.php, admin/views/cookies.php
Aggiungono notice nascoste di default con messaggio, area aria-live e template testuale usati dal watchdog.
Test e2e del watchdog
tests/e2e/specs/admin-blocked-script-watchdog.spec.ts
Nuova suite Playwright che simula il blocco dello script e verifica comparsa/scomparsa della notice in base ai flag di boot.

Estimated code review effort: 2 (Simple) | ~15 minutes

Related PRs: Nessuna informazione disponibile nel contesto fornito.

Suggested labels: enhancement, accessibility, tests

Suggested reviewers: Nessuna informazione disponibile nel contesto fornito.

Poem: Un coniglio digitale scava nel codice quieto, / tra flag booleani e un template segreto. / Se un ad-blocker ferma lo script in corsa, / spunta la notice, l'annuncio si forza. / E-e-test verificano tutto in un balzo lieto! 🐰

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed Il titolo descrive correttamente il nuovo avviso watchdog admin per i file cookie-policy.js e cookies.js bloccati da ad blocker.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/admin-blocked-script-watchdog

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 PHPStan (2.2.2)

PHPStan was skipped because the config uses disallowed bootstrapFiles, bootstrapFile, or includes directives.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

reveal() set msg.textContent = tpl.innerHTML, which re-serializes the <template>'s
parsed content back into HTML entities and then writes the literal entity (e.g.
&amp;) for any localized string containing &, <, or >. Read tpl.content.textContent
instead — the parsed DocumentFragment's decoded text. (No effect on the shipped
English string, which has no such characters; this hardens localized strings.)
@fabiodalez-dev fabiodalez-dev merged commit a932b2f into main Jul 2, 2026
5 checks passed
@fabiodalez-dev fabiodalez-dev deleted the fix/admin-blocked-script-watchdog branch July 2, 2026 14:28
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.

1 participant