@@ -24,20 +24,55 @@ function onMessage(message, sender, sendResponse) {
2424 }
2525}
2626
27+ // /**
28+ // * Extract links
29+ // * @function extractAllLinks
30+ // * @return {Array }
31+ // */
32+ // function extractAllLinks() {
33+ // console.debug('extractAllLinks')
34+ // const links = []
35+ // for (const element of document.links) {
36+ // if (element.href) {
37+ // pushElement(links, element)
38+ // }
39+ // }
40+ // console.debug('links:', links)
41+ // return links
42+ // }
43+
2744/**
2845 * Extract links
2946 * @function extractAllLinks
3047 * @return {Array }
3148 */
3249function extractAllLinks ( ) {
3350 console . debug ( 'extractAllLinks' )
51+ const links = findLinks ( document )
52+ console . debug ( 'links:' , links )
53+ return links
54+ }
55+
56+ /**
57+ * Recursively Find Links from shadowRoot
58+ * @function findLinks
59+ * @param {Document|ShadowRoot } root
60+ * @return {Array }
61+ */
62+ function findLinks ( root ) {
63+ console . debug ( 'findLinks:' , root )
3464 const links = [ ]
35- for ( const element of document . links ) {
36- if ( element . href ) {
37- pushElement ( links , element )
38- }
65+ if ( root . querySelectorAll ) {
66+ root . querySelectorAll ( 'a' ) . forEach ( ( el ) => {
67+ pushElement ( links , el )
68+ } )
3969 }
40- console . debug ( 'links:' , links )
70+ const roots = Array . from ( root . querySelectorAll ( '*' ) ) . filter (
71+ ( el ) => el . shadowRoot
72+ )
73+ roots . forEach ( ( el ) => {
74+ links . push ( ...findLinks ( el . shadowRoot ) )
75+ } )
4176 return links
4277}
4378
0 commit comments