| () => { | |
| // Retain node objects outside page-authored attributes. Include open shadow roots. | |
| const nodes = [], paths = []; | |
| const walk = (root, parentPath) => { | |
| let index = 0; | |
| for (const el of root.children || []) { | |
| const path = [...parentPath, index++]; | |
| if (el.matches('a[href],button,input,textarea,select,summary,[role],[tabindex],[contenteditable="true"],h1,h2,h3,p,output')) { | |
| nodes.push(el); | |
| paths.push(path.join('/')); | |
| } | |
| if (el.shadowRoot) walk(el.shadowRoot, path); | |
| walk(el, path); | |
| } | |
| }; | |
| walk(document, []); | |
| return {nodes, paths}; | |
| } | |