When inserting a script into the shadow root of an element is there a way to refer to the host element?
var element = document.createElement('div');
var script = document.createElement('script');
script.innerHTML = 'console.log(host)'; // << How to get host element??
var shadow = element.createShadowRoot();
shadow.appendChild(script);
document.body.appendChild(element);
Node.getRootNode()
was introduced in 2016.
You can now access the host element like so:
element.getRootNode().host