File size: 608 Bytes
795f737
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
() => {
  // 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};
}