Skip to content

Add shadow DOM support for text spacing styles #33

Open
ritz078 wants to merge 2 commits intoactum:mainfrom
ritz078:shadow-dom-support
Open

Add shadow DOM support for text spacing styles #33
ritz078 wants to merge 2 commits intoactum:mainfrom
ritz078:shadow-dom-support

Conversation

@ritz078
Copy link

@ritz078 ritz078 commented Feb 13, 2026

Currently, text spacing styles injected by the extension via chrome.scripting.insertCSS() only apply at the document level and cannot cross shadow DOM boundaries. Users visiting pages with web components (which use open shadow DOM) see no text spacing applied inside those components. This also affects shadow DOMs nested within iframes.

How it is solved

  • Extracted CSS string building logic into a shared reusable helper
  • Added a Plasmo content script that runs on all pages and frames (including about:blank iframes) at document_idle
  • The content script walks the DOM tree, finds elements with open shadowRoot, and injects a <style> element into each shadow root
  • A MutationObserver detects dynamically added elements with shadow roots, with a deferred requestAnimationFrame re-check for components that attach shadow roots in connectedCallback()
  • Storage changes (styles/enabled toggle) are watched to keep shadow-injected styles in sync in real time
  • Fixed a pre-existing bug where empty CSS property values produced invalid CSS (missing semicolons) that broke subsequent declarations

What this enables

  • Text spacing styles now apply inside open shadow DOM components
  • Nested shadow DOMs are handled recursively
  • Shadow DOMs inside iframes (including about:blank frames) are supported
  • Fixed invalid CSS generation when only some spacing properties are set

Risks / notes

  • Only open shadow DOMs are supported — closed shadow DOMs are inaccessible by design and cannot be styled
  • Cross-origin iframes with restrictive CSP may still block the content script from executing

closes #32

Inject styles into open shadow DOM boundaries via a content script
that walks the DOM, finds shadow roots, and injects <style> elements.
Uses MutationObserver to handle dynamically added shadow roots.
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.

Add support for Shadow DOM open mode

1 participant