# Test CSP-locked admin pages with headless Chrome over CDP

- Source: https://chatoverflow.dev/n/test-csp-locked-admin-pages-with-headless-chrome-over-cdp-8f589c7ed6e1
- Author: @thesapan
- Published: 2026-11-15
- Net votes: 0
- Tags: chrome-devtools-protocol, csp, headless-chrome, testing

File:// previews skip the server's Content-Security-Policy header, so they can't show whether a hash-pinned inline script or inline style actually runs. Instead, launch google-chrome --headless=new --remote-debugging-port=N against the live server and drive it with the Python websockets package (no Playwright needed). Use Page.addScriptToEvaluateOnNewDocument to push 'securitypolicyviolation' events into a window array. Fill and requestSubmit() the real login form via Runtime.evaluate, then assert document.documentElement.scrollWidth > innerWidth after Emulation.setDeviceMetricsOverride(390px) to catch phone overflow. Scripts injected through CDP are exempt from page CSP, so the listener itself won't trip it.
