Skip to content

Commit b7b2a91

Browse files
authored
Finish shadowRoot Extraction (#87)
* Finish shadowRoot Extraction * Add shadowRoot Test
1 parent def42c4 commit b7b2a91

File tree

2 files changed

+38
-18
lines changed

2 files changed

+38
-18
lines changed

src/js/extract.js

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ function extractAllLinks() {
6060
* @return {Array}
6161
*/
6262
function findLinks(root) {
63-
console.debug('findLinks:', root)
63+
// console.debug('findLinks:', root)
6464
const links = []
6565
if (root.querySelectorAll) {
66-
root.querySelectorAll('a').forEach((el) => {
66+
root.querySelectorAll('a, area').forEach((el) => {
6767
pushElement(links, el)
6868
})
6969
}
@@ -95,9 +95,10 @@ function extractSelection() {
9595
if (ancestor.nodeName === '#text') {
9696
continue
9797
}
98-
ancestor.querySelectorAll('a').forEach((element) => {
99-
if (selection.containsNode(element, true)) {
100-
pushElement(links, element)
98+
ancestor.querySelectorAll('a, area').forEach((el) => {
99+
if (selection.containsNode(el, true)) {
100+
// console.debug('el:', el)
101+
pushElement(links, el)
101102
}
102103
})
103104
}
@@ -114,16 +115,18 @@ function extractSelection() {
114115
function pushElement(array, element) {
115116
// console.debug('element:', element)
116117
try {
117-
const data = {
118-
href: decodeURI(element.href),
119-
text: element.textContent?.trim(),
120-
title: element.title,
121-
label: element.ariaLabel || '',
122-
rel: element.rel,
123-
target: element.target,
124-
origin: element.origin,
118+
if (element.href) {
119+
const data = {
120+
href: decodeURI(element.href),
121+
text: element.textContent?.trim(),
122+
title: element.title,
123+
label: element.ariaLabel || '',
124+
rel: element.rel,
125+
target: element.target,
126+
origin: element.origin,
127+
}
128+
array.push(data)
125129
}
126-
array.push(data)
127130
} catch (e) {
128131
console.log(e)
129132
}

tests/test.mjs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,31 @@ async function screenshot(name) {
7070

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

7777
page = await getPage(browser, 'links.html', true, '768x920')
7878
console.log('page:', page)
7979
await page.waitForNetworkIdle()
80-
await screenshot('links')
80+
await screenshot('link-extractor')
81+
82+
// Page
83+
await page.goto('https://archive.org/')
84+
page.on('console', (msg) => console.log(`console: page:`, msg.text()))
85+
await page.bringToFront()
86+
await page.waitForNetworkIdle()
87+
88+
// Links
89+
await worker.evaluate('chrome.action.openPopup();')
90+
let popup2 = await getPage(browser, 'popup.html', true)
91+
console.log('popup2:', popup2)
92+
await popup2.locator('a[data-filter=""]').click()
93+
94+
page = await getPage(browser, 'links.html', true, '768x920')
95+
console.log('page:', page)
96+
await page.waitForNetworkIdle()
97+
await screenshot('archive.org')
8198

8299
await browser.close()
83100
})()

0 commit comments

Comments
 (0)