{"ScriptPreparationCode":"for (let i = 1; i \u003C 300; i\u002B\u002B) {\r\n const wrapper = document.createElement(\u0027div\u0027);\r\n const shadowRoot = wrapper.attachShadow({\r\n mode: \u0027open\u0027\r\n });\r\n shadowRoot.innerHTML = \u0060\r\n \u003Cdiv\u003E\r\n \u003Cform id=\u0022login\u0022\u003E\r\n \u003Cinput type=\u0022text\u0022 id=\u0022field1\u0022\u003E\u003Cbr\u003E\r\n \u003Cinput type=\u0022password\u0022 id=\u0022field2\u0022\u003E\u003Cbr\u003E\r\n \u003Cinput type=\u0022submit\u0022 id=\u0022field3\u0022 value=\u0022Submit\u0022\u003E\r\n \u003C/form\u003E\r\n \u003C/div\u003E\r\n \u0060;\r\n}","TestCases":[{"Name":"flatMap","Code":"function getShadowRoot(el) {\r\n if (!(el instanceof HTMLElement)) {\r\n return undefined;\r\n }\r\n if (window.chrome?.dom?.openOrClosedShadowRoot) {\r\n return window.chrome.dom.openOrClosedShadowRoot(el) ?? undefined;\r\n }\r\n if (el.openOrClosedShadowRoot) {\r\n return el.openOrClosedShadowRoot;\r\n }\r\n return el.shadowRoot ?? undefined;\r\n}\r\n \r\nfunction querySelectorAllWithShadowRoots(\r\n selector,\r\n rootNode = document\r\n) {\r\n // this is always in document order according to querySelectorAll specification\r\n const allEls = Array.from(rootNode.querySelectorAll(\u0027*\u0027));\r\n const selectedEls = new Set(rootNode.querySelectorAll(selector));\r\n\r\n // Map across all els, and insert els from shadow root at the correct location to retain document\r\n // order.\r\n return allEls.flatMap((el) =\u003E {\r\n const result = [];\r\n if (selectedEls.has(el)) {\r\n result.push(el);\r\n }\r\n const shadowRoot = getShadowRoot(el);\r\n if (shadowRoot) {\r\n result.push(...querySelectorAllWithShadowRoots(selector, shadowRoot));\r\n }\r\n return result;\r\n });\r\n}\r\n\r\nquerySelectorAllWithShadowRoots(\u0027input\u0027);","IsDeferred":false},{"Name":"results closure","Code":"function getShadowRoot(el) {\r\n if (!(el instanceof HTMLElement)) {\r\n return undefined;\r\n }\r\n if (window.chrome?.dom?.openOrClosedShadowRoot) {\r\n return window.chrome.dom.openOrClosedShadowRoot(el) ?? undefined;\r\n }\r\n if (el.openOrClosedShadowRoot) {\r\n return el.openOrClosedShadowRoot;\r\n }\r\n return el.shadowRoot ?? undefined;\r\n}\r\n\r\nfunction querySelectorAllWithShadowRoots(\r\n selector,\r\n rootNode = document\r\n) {\r\n const result = [];\r\n const findInRoot = (rootNode) =\u003E {\r\n // this is always in document order according to querySelectorAll specification\r\n const allEls = Array.from(rootNode.querySelectorAll(\u0027*\u0027));\r\n const selectedEls = new Set(rootNode.querySelectorAll(selector));\r\n\r\n for (const el of allEls) {\r\n if (selectedEls.has(el)) {\r\n result.push(el);\r\n }\r\n const shadowRoot = getShadowRoot(el);\r\n if (shadowRoot) {\r\n findInRoot(shadowRoot);\r\n }\r\n }\r\n };\r\n findInRoot(rootNode);\r\n return result;\r\n}\r\n\r\nquerySelectorAllWithShadowRoots(\u0027input\u0027);","IsDeferred":false}]}