I'm working in a project which uses Polymer (still on 1.7, we'll relaunch using a different technology instead of upgrading...) and I'm supposed to check out the possibilities to make it work together with DynamicYield, which is a personalization platform that injects HTML of personalized items or recommendations into one's page via ShadowDOM.
The problem with shadowDOM is that, of course, your site's styles are missing, meaning you'd have to inject all your styles and thus maintain them in DynamicYield.
So my idea is to take the injected content and get it out of the shadow DOM. I tried to type something like
document.getElementById('rec').innerHTML = document.getElementById('rec').shadowRoot.innerHTML;
document.getElementById('rec').shadowRoot.innerHTML = '';
... into the JS console, but, although the DOM looks good now, the content disappered from the visible site. (Maybe that's a Polymer issue?)
Do you have any ideas what I could do to use the main sites styles inside the injected code? The DynamicYield docs unfortunately don't mention any setting to prevent it from using ShadowDOM (apart from unsetting the SPA_FLOW flag which is not feasible in our case).
EDIT: Adding a small snippet to show the problem. Use inspect to see the innerHTML is in div#rec but not visible.
//Simulating DynamicYield adding code. Second headline/Shadow DOM will NOT be green.
const el = document.getElementById('rec');
const shadowRoot = el.attachShadow({mode: 'open'});
shadowRoot.innerHTML = '<h1>I belong to Shadow DOM</h1>';
const container = document.querySelector('body');
container.appendChild(el);
//Trying to get Code out of Shadow DOM
el.innerHTML = el.shadowRoot.innerHTML;
el.shadowRoot.innerHTML = '';
h1 {
color: green;
}
<h1>I belong to Light DOM</h1>
<div id="rec"></div>