(
element: HTMLElement | ShadowRoot,
includeSelectorTag: boolean,
shadowElementIds: [string, HTMLElement, HTMLElement | undefined][] = []
)
| 7 | * @return {Object} html source and list of shadow root ids found |
| 8 | */ |
| 9 | export default function getHTMLShadow ( |
| 10 | element: HTMLElement | ShadowRoot, |
| 11 | includeSelectorTag: boolean, |
| 12 | shadowElementIds: [string, HTMLElement, HTMLElement | undefined][] = [] |
| 13 | ) { |
| 14 | shadowElementIds.map(([id, elem]) => { |
| 15 | /** |
| 16 | * if we don't have a shadow root (e.g. most likely to be the root document node) |
| 17 | */ |
| 18 | if (typeof elem.setAttribute !== 'function') { |
| 19 | return |
| 20 | } |
| 21 | |
| 22 | elem.setAttribute('data-wdio-shadow-id', id) |
| 23 | }) |
| 24 | |
| 25 | const shadowElementHTML = shadowElementIds.map(([id, elem, shadow]) => { |
| 26 | /** |
| 27 | * if we don't have a shadow root (e.g. most likely to be the root document node) |
| 28 | * we just get the html of the element |
| 29 | */ |
| 30 | if (!shadow) { |
| 31 | const html = elem[includeSelectorTag ? 'outerHTML' : 'innerHTML'] |
| 32 | return { id, html } |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * otherwise, we look up the registered shadow styles and html |
| 37 | */ |
| 38 | const styles = Array.from((shadow as unknown as ShadowRoot).adoptedStyleSheets || []) |
| 39 | .map(({ cssRules }) => Array.from(cssRules)) |
| 40 | .flat() |
| 41 | .map(({ cssText }) => cssText) |
| 42 | |
| 43 | const html = shadow.innerHTML |
| 44 | return { id, html, styles } |
| 45 | }) |
| 46 | |
| 47 | return { |
| 48 | html: (element as HTMLElement)[includeSelectorTag ? 'outerHTML' : 'innerHTML'], |
| 49 | shadowElementHTML |
| 50 | } |
| 51 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…