embed-page
embed-page copied to clipboard
document.currentScript is not defined when executing in scope="none"
For microapplication concept it is crucial to have an embedded script serving and accessing the content directly around the script without the need to identify the surrounding DOM. I.e. ability to traverse DOM starting from current script. The way around like dom identified with ID unfortunately is not universal as it could be multiple microapplications ( including same type ) presented on same host page. The dom insulation is not always applicable as scope=none disables insulation.
The cause of currentScript is not defined is in dynamic script loading. Under standard only scripts which are part of initial HTML will be given document.curentScript set.
https://github.com/whatwg/html/issues/1013 states the interest for currentScript availability in shadowDom.
Work around: plug-in to module loader (xhr/workers/etc) and define the alternative variable in document scope. document.currentModule
with SCRIPT object, for ES6 modules the parentNode would refer to parent module, question is how to associate the instance and module since the actual use is to get the HtmlElement instance reference from module. I.e. get current script or ownerElement in order to access other elements within shadowDom.
In embed-page document.epaCurrentScript will serve as surrogate.
https://github.com/EPA-WG/embed-page/issues/11