cssnr / link-extractor

Web Extension to extract, parse, and open links with optional filters.
https://link-extractor.cssnr.com
GNU General Public License v3.0
16 stars 2 forks source link

Find Links in shadowRoot's #80

Closed smashedr closed 18 hours ago

smashedr commented 1 week ago

Links are not being extracted from shadowRoots. Will need to add a recursive function to extract from nested roots:

function getAllLinks(root) {
    let links = []
    if (root.querySelectorAll) {
        links = Array.from(root.querySelectorAll('a'))
    }
    const shadowRoots = Array.from(root.querySelectorAll('*')).filter(
        (el) => el.shadowRoot
    )
    shadowRoots.forEach((el) => {
        links = links.concat(getAllLinks(el.shadowRoot))
    })
    return links
}

const allLinks = getAllLinks(document)
console.log(allLinks)

Example Site: https://archive.org/

I will try to add a fix for this in the next version.
Thank you to feedback reports for surfacing this issue.