- From: Russell <notifications@github.com>
- Date: Sat, 14 May 2022 11:03:21 -0700
- To: WICG/webcomponents <webcomponents@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
Received on Saturday, 14 May 2022 18:03:33 UTC
I came up with [a solution](https://stackoverflow.com/a/72242132/6036546) to this problem. I used a custom element in the linked example but it's not necessary. It can also work from outside of a closed shadowRoot with a few tweaks like this : ``` <div id="test"></div> <script type="module"> const host = document.querySelector('#test'); const shadowRoot = host.attachShadow({ mode:'closed' }); const scopedEval = (script,scope) => Function(script).bind(scope)(); shadowRoot.innerHTML = `<script>console.log(this, this.host);<\/script>`; const scripts = shadowRoot.querySelectorAll('script'); scripts.forEach(s => scopedEval(s.innerHTML, shadowRoot)); </script> ``` -- Reply to this email directly or view it on GitHub: https://github.com/WICG/webcomponents/issues/717#issuecomment-1126786185 You are receiving this because you are subscribed to this thread. Message ID: <WICG/webcomponents/issues/717/1126786185@github.com>
Received on Saturday, 14 May 2022 18:03:33 UTC