Skip to content

Commit

Permalink
Finish shadowRoot Extraction (#87)
Browse files Browse the repository at this point in the history
* Finish shadowRoot Extraction

* Add shadowRoot Test
  • Loading branch information
smashedr authored Jul 6, 2024
1 parent def42c4 commit b7b2a91
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 18 deletions.
31 changes: 17 additions & 14 deletions src/js/extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ function extractAllLinks() {
* @return {Array}
*/
function findLinks(root) {
console.debug('findLinks:', root)
// console.debug('findLinks:', root)
const links = []
if (root.querySelectorAll) {
root.querySelectorAll('a').forEach((el) => {
root.querySelectorAll('a, area').forEach((el) => {
pushElement(links, el)
})
}
Expand Down Expand Up @@ -95,9 +95,10 @@ function extractSelection() {
if (ancestor.nodeName === '#text') {
continue
}
ancestor.querySelectorAll('a').forEach((element) => {
if (selection.containsNode(element, true)) {
pushElement(links, element)
ancestor.querySelectorAll('a, area').forEach((el) => {
if (selection.containsNode(el, true)) {
// console.debug('el:', el)
pushElement(links, el)
}
})
}
Expand All @@ -114,16 +115,18 @@ function extractSelection() {
function pushElement(array, element) {
// console.debug('element:', element)
try {
const data = {
href: decodeURI(element.href),
text: element.textContent?.trim(),
title: element.title,
label: element.ariaLabel || '',
rel: element.rel,
target: element.target,
origin: element.origin,
if (element.href) {
const data = {
href: decodeURI(element.href),
text: element.textContent?.trim(),
title: element.title,
label: element.ariaLabel || '',
rel: element.rel,
target: element.target,
origin: element.origin,
}
array.push(data)
}
array.push(data)
} catch (e) {
console.log(e)
}
Expand Down
25 changes: 21 additions & 4 deletions tests/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,31 @@ async function screenshot(name) {

// Links
await worker.evaluate('chrome.action.openPopup();')
let popupPage = await getPage(browser, 'popup.html', true)
console.log('popupPage:', popupPage)
await popupPage.locator('a[data-filter=""]').click()
let popup1 = await getPage(browser, 'popup.html', true)
console.log('popup1:', popup1)
await popup1.locator('a[data-filter=""]').click()

page = await getPage(browser, 'links.html', true, '768x920')
console.log('page:', page)
await page.waitForNetworkIdle()
await screenshot('links')
await screenshot('link-extractor')

// Page
await page.goto('https://archive.org/')
page.on('console', (msg) => console.log(`console: page:`, msg.text()))
await page.bringToFront()
await page.waitForNetworkIdle()

// Links
await worker.evaluate('chrome.action.openPopup();')
let popup2 = await getPage(browser, 'popup.html', true)
console.log('popup2:', popup2)
await popup2.locator('a[data-filter=""]').click()

page = await getPage(browser, 'links.html', true, '768x920')
console.log('page:', page)
await page.waitForNetworkIdle()
await screenshot('archive.org')

await browser.close()
})()

0 comments on commit b7b2a91

Please sign in to comment.