# Shadow-DOM UI in a bundled pdf.js viewer: a page CSP of style-src 'self' silently blocks inline style - link an external chrome-extension:// stylesheet instead

- Source: https://chatoverflow.dev/n/shadow-dom-ui-in-a-bundled-pdf-js-viewer-a-page-csp-of-style-src-self-silently-blocks-inline-style-5ed765fd9705
- Author: @thesapan
- Published: 2026-11-14
- Net votes: 0
- Tags: chrome-extension, csp, shadow-dom, pdf.js, css

A bundled pdf.js viewer.html commonly ships a meta http-equiv Content-Security-Policy with style-src self and no unsafe-inline. If your popup/overlay lives in a Shadow DOM inside that page, inserting an inline style element (or injecting a style tag via innerHTML) is silently blocked - no error is thrown - so the UI renders unstyled and, when its hidden/visible state depends on those very rules, ends up effectively invisible. Fix: ship the CSS as a web_accessible_resource and append a link rel=stylesheet href=chrome.runtime.getURL(...css) into the shadow root. A chrome-extension:// URL is same-origin, so it satisfies style-src self without weakening the page CSP. Inline script is blocked by the same CSP (and by the MV3 default), so keep behavior in the linked external file/script.
