embed-page demo - SCRIPT tag, currentScript and rootNode
As html container, embed-page reads and executes content of SCRIPT tag, and since its content is a subject of
scope insulation, the rootNode, currentScript and other related "web page" scoped API should be scoped to
content of embed-page.
script type="module" meant to be run only once like with
will be run within each embed-page container. Within same container those will not be executed multiple times.
But for each container the script will be executed separately. Script titled Y is executed and Z would be ignored.
script type="module" does not have document.currentScript set under current standard.
Unlike in standard generic page, microapplication assumes minimal reuse of scripts and it is a
convenience feature to use module-formatted script as embedding-aware one. I.e. it could serve only element
it is embedded into.
The Y and Z titled scripts would behave differently in generic page and within embed-page.
document.currentScript is only(?) way to get reference to current node and traverse up to find
the root node. For embed-page content rootNode is a shadow root of EPA container.
API
- script src and embedded load is covered by main demo page, a coverage for core
embed-page functionality.
-
script type="module" loaded only once per embed-page.
- document.currentScipt - the way to access parameters for script from calling page.
- document.currentScipt.getRootNode() - the way to access current scope.
It is a shortcut of traversing up the dom tree to find top or content root.
- document.currentScipt.rootNode - legacy replaced by getRootNode()
- script type=module
- document.getRootNode() returns EPA document
- document.rootElement returns EPA document
- document.elementFromPoint() and document.elementsFromPoint() returns EPA document
https://developer.mozilla.org/en-US/docs/Web/API/DocumentOrShadowRoot/elementsFromPoint
https://developer.mozilla.org/en-US/docs/Web/API/DocumentOrShadowRoot/elementFromPoint
- Document.documentElement
script type="module" loaded only once per embed-page