glidercli 0.4.14 → 0.4.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +78 -95
- package/bin/glider.js +175 -147
- package/config/browser.json.example +1 -3
- package/config/browsers-registry.json.example +39 -0
- package/config/domains.template.json +1 -1
- package/docs/setup.json +7 -7
- package/lib/bexplore.js +228 -142
- package/lib/browser-config.js +1 -1
- package/lib/glider-daemon.sh +133 -6
- package/lib/paths.js +5 -7
- package/package.json +2 -2
package/docs/setup.json
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
},
|
|
14
14
|
"requirements": {
|
|
15
15
|
"node": ">=18",
|
|
16
|
-
"browser": "Chromium-based (Chrome
|
|
16
|
+
"browser": "Chromium-based (Chrome default; Edge, Brave, Opera, Vivaldi, Helium, Arc); see README Browsers section",
|
|
17
17
|
"os": "macOS (tested), Linux (untested), Windows (untested)"
|
|
18
18
|
},
|
|
19
19
|
"install": {
|
|
@@ -35,14 +35,14 @@
|
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
37
|
"config_paths": {
|
|
38
|
-
"glider_home": "$
|
|
39
|
-
"domains": "$
|
|
38
|
+
"glider_home": "$GLIDER (default: $HOME/.glider)",
|
|
39
|
+
"domains": "$GLIDER/config/domains.json",
|
|
40
40
|
"domains_template": "config/domains.template.json (shipped in package)",
|
|
41
|
-
"warch_root": "
|
|
42
|
-
"registry_base": "
|
|
41
|
+
"warch_root": "$GLIDER/warch/<host>/ (glider.json, gotchas.json, bexplore/)",
|
|
42
|
+
"registry_base": "$GLIDER",
|
|
43
43
|
"resolve": "glider resolve <url> --json",
|
|
44
|
-
"browser": "$
|
|
45
|
-
"daemon_log": "$
|
|
44
|
+
"browser": "$GLIDER/config/browser.json",
|
|
45
|
+
"daemon_log": "$GLIDER/daemon.log"
|
|
46
46
|
},
|
|
47
47
|
"discovery": "glider --help"
|
|
48
48
|
}
|
package/lib/bexplore.js
CHANGED
|
@@ -39,6 +39,46 @@ function pathTemplate(pathname) {
|
|
|
39
39
|
.replace(/\/wiki\/[^/]+/i, '/wiki/{page}');
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
function sameOriginUrl(url, startOrigin, startHref) {
|
|
43
|
+
if (!url || !startOrigin) return false;
|
|
44
|
+
try {
|
|
45
|
+
return new URL(url, startHref || undefined).origin === startOrigin;
|
|
46
|
+
} catch {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function createEnqueue({ startOrigin, startHref, templateHits, cap, seen, push }) {
|
|
52
|
+
const hits = templateHits || new Map();
|
|
53
|
+
const seenSet = seen || new Set();
|
|
54
|
+
const limit = cap == null ? PATH_TEMPLATE_CAP : cap;
|
|
55
|
+
return function enqueue(href) {
|
|
56
|
+
if (!href || !sameOriginUrl(href, startOrigin, startHref)) return false;
|
|
57
|
+
let pathName = href;
|
|
58
|
+
try { pathName = new URL(href, startHref).pathname; } catch (_) {}
|
|
59
|
+
const tmpl = pathTemplate(pathName);
|
|
60
|
+
if ((hits.get(tmpl) || 0) >= limit) return false;
|
|
61
|
+
const norm = String(href).split('#')[0];
|
|
62
|
+
if (seenSet.has(norm)) return false;
|
|
63
|
+
seenSet.add(norm);
|
|
64
|
+
hits.set(tmpl, (hits.get(tmpl) || 0) + 1);
|
|
65
|
+
if (typeof push === 'function') push(norm);
|
|
66
|
+
return true;
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function harDocumentUrls(requests, fromIndex) {
|
|
71
|
+
const out = [];
|
|
72
|
+
const start = Math.max(0, fromIndex | 0);
|
|
73
|
+
const list = Array.isArray(requests) ? requests : [];
|
|
74
|
+
for (let i = start; i < list.length; i++) {
|
|
75
|
+
const r = list[i];
|
|
76
|
+
if (!r || !r.url) continue;
|
|
77
|
+
if (r.type === 'Document') out.push(r.url);
|
|
78
|
+
}
|
|
79
|
+
return out;
|
|
80
|
+
}
|
|
81
|
+
|
|
42
82
|
class WorkQueue {
|
|
43
83
|
constructor() {
|
|
44
84
|
this.q = [];
|
|
@@ -130,8 +170,10 @@ class SiteExplorer {
|
|
|
130
170
|
sidePanels: [],
|
|
131
171
|
dropdowns: [],
|
|
132
172
|
checkboxes: [],
|
|
173
|
+
clickables: [],
|
|
133
174
|
screenshots: []
|
|
134
175
|
};
|
|
176
|
+
this._enqueue = null;
|
|
135
177
|
}
|
|
136
178
|
|
|
137
179
|
async connect() {
|
|
@@ -432,24 +474,23 @@ class SiteExplorer {
|
|
|
432
474
|
modals: [],
|
|
433
475
|
filters: [],
|
|
434
476
|
pagination: null,
|
|
477
|
+
pagers: [],
|
|
435
478
|
infiniteScroll: false,
|
|
436
479
|
sidePanels: [],
|
|
437
480
|
dropdowns: [],
|
|
438
481
|
checkboxes: [],
|
|
439
|
-
inputs: []
|
|
482
|
+
inputs: [],
|
|
483
|
+
clickables: []
|
|
440
484
|
};
|
|
485
|
+
const seenEl = new Set();
|
|
441
486
|
|
|
442
|
-
// Helper: generate best selector for element
|
|
443
487
|
const getSelector = (el) => {
|
|
444
488
|
try {
|
|
445
489
|
const qa = el.getAttribute('data-qa');
|
|
446
|
-
if (qa) return '[data-qa="' + qa.replace(/"/g, '
|
|
447
|
-
|
|
490
|
+
if (qa) return '[data-qa="' + qa.replace(/"/g, '\\\\"') + '"]';
|
|
448
491
|
const ariaLabel = el.getAttribute('aria-label');
|
|
449
|
-
if (ariaLabel) return '[aria-label="' + ariaLabel.replace(/"/g, '
|
|
450
|
-
|
|
492
|
+
if (ariaLabel) return '[aria-label="' + ariaLabel.replace(/"/g, '\\\\"') + '"]';
|
|
451
493
|
if (el.id) return '#' + CSS.escape(el.id);
|
|
452
|
-
|
|
453
494
|
const classes = Array.from(el.classList).filter(c => !c.includes('--') && c.length > 2);
|
|
454
495
|
for (const cls of classes) {
|
|
455
496
|
try {
|
|
@@ -457,8 +498,6 @@ class SiteExplorer {
|
|
|
457
498
|
if (document.querySelectorAll(sel).length === 1) return sel;
|
|
458
499
|
} catch (_) {}
|
|
459
500
|
}
|
|
460
|
-
|
|
461
|
-
// Build nth-child path (last resort)
|
|
462
501
|
const path = [];
|
|
463
502
|
let current = el;
|
|
464
503
|
while (current && current !== document.body) {
|
|
@@ -469,56 +508,91 @@ class SiteExplorer {
|
|
|
469
508
|
const tag = current.tagName.toLowerCase();
|
|
470
509
|
path.unshift(tag + ':nth-child(' + index + ')');
|
|
471
510
|
current = parent;
|
|
472
|
-
if (path.length > 4) break;
|
|
511
|
+
if (path.length > 4) break;
|
|
473
512
|
}
|
|
474
513
|
return path.join(' > ') || null;
|
|
475
514
|
} catch (_) { return null; }
|
|
476
515
|
};
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
document.querySelectorAll('[role="tab"], .tab, [data-tab], .nav-item, .nav-link, [class*="tab"]').forEach(el => {
|
|
480
|
-
result.tabs.push({
|
|
481
|
-
text: el.textContent?.trim().slice(0, 50),
|
|
482
|
-
selector: getSelector(el),
|
|
483
|
-
active: el.classList.contains('active') || el.getAttribute('aria-selected') === 'true'
|
|
484
|
-
});
|
|
485
|
-
});
|
|
486
|
-
|
|
487
|
-
// Buttons
|
|
488
|
-
document.querySelectorAll('button, [role="button"], input[type="button"], input[type="submit"], .btn, [class*="button"]').forEach(el => {
|
|
516
|
+
|
|
517
|
+
const vis = (el) => {
|
|
489
518
|
const r = el.getBoundingClientRect();
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
519
|
+
return (r.width > 0 || r.height > 0) && !el.disabled;
|
|
520
|
+
};
|
|
521
|
+
|
|
522
|
+
const walk = (root, fn) => {
|
|
523
|
+
if (!root || !root.querySelectorAll) return;
|
|
524
|
+
root.querySelectorAll('*').forEach((el) => {
|
|
525
|
+
fn(el);
|
|
526
|
+
if (el.shadowRoot) walk(el.shadowRoot, fn);
|
|
497
527
|
});
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
// Links (internal only)
|
|
528
|
+
};
|
|
529
|
+
|
|
501
530
|
const startOrigin = ${JSON.stringify(this.startOrigin || '')};
|
|
502
531
|
const hostOk = (href) => {
|
|
503
|
-
try { return new URL(href).origin === startOrigin; } catch { return false; }
|
|
532
|
+
try { return new URL(href, location.href).origin === startOrigin; } catch { return false; }
|
|
504
533
|
};
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
534
|
+
|
|
535
|
+
const clickRole = /^(button|tab|menuitem|menuitemcheckbox|menuitemradio|link|option|switch)$/;
|
|
536
|
+
const isClickable = (el) => {
|
|
537
|
+
const tag = el.tagName;
|
|
538
|
+
const role = (el.getAttribute('role') || '').toLowerCase();
|
|
539
|
+
if (tag === 'BUTTON') return true;
|
|
540
|
+
if (tag === 'A' && el.getAttribute('href')) return true;
|
|
541
|
+
if (clickRole.test(role)) return true;
|
|
542
|
+
if (tag === 'INPUT' && /^(button|submit|reset|checkbox)$/i.test(el.type || '')) return true;
|
|
543
|
+
if (el.hasAttribute('onclick')) return true;
|
|
544
|
+
if (el.hasAttribute('tabindex') && el.tabIndex >= 0 && tag !== 'INPUT' && tag !== 'TEXTAREA' && tag !== 'SELECT') return true;
|
|
545
|
+
const cls = String(el.className || '');
|
|
546
|
+
if (/load-?more|page-link|pagination/i.test(cls) && (tag === 'A' || tag === 'BUTTON' || role === 'button')) return true;
|
|
547
|
+
return false;
|
|
548
|
+
};
|
|
549
|
+
|
|
550
|
+
const rec = (kind, el, extra) => {
|
|
551
|
+
if (seenEl.has(el) || !vis(el)) return;
|
|
552
|
+
seenEl.add(el);
|
|
553
|
+
const item = Object.assign({
|
|
554
|
+
kind,
|
|
555
|
+
text: (el.textContent || '').trim().slice(0, 50) || el.value || el.getAttribute('aria-label'),
|
|
556
|
+
selector: getSelector(el),
|
|
557
|
+
label: el.getAttribute('aria-label'),
|
|
558
|
+
href: el.href || el.getAttribute('href') || null
|
|
559
|
+
}, extra || {});
|
|
560
|
+
result.clickables.push(item);
|
|
561
|
+
return item;
|
|
562
|
+
};
|
|
563
|
+
|
|
564
|
+
walk(document, (el) => {
|
|
565
|
+
const tag = el.tagName;
|
|
566
|
+
const role = (el.getAttribute('role') || '').toLowerCase();
|
|
567
|
+
if (role === 'tab' || el.matches && el.matches('[data-tab], .tab, .nav-item, .nav-link')) {
|
|
568
|
+
const item = rec('tab', el, { active: el.classList.contains('active') || el.getAttribute('aria-selected') === 'true' });
|
|
569
|
+
if (item) result.tabs.push(item);
|
|
570
|
+
}
|
|
571
|
+
if (tag === 'BUTTON' || role === 'button' || (tag === 'INPUT' && /^(button|submit)$/i.test(el.type || '')) || (el.classList && (el.classList.contains('btn') || /button/i.test(el.className || '')))) {
|
|
572
|
+
const item = rec('button', el, { type: el.type || 'button', qa: el.getAttribute('data-qa') });
|
|
573
|
+
if (item) result.buttons.push(item);
|
|
574
|
+
}
|
|
575
|
+
if (tag === 'A' && el.href && hostOk(el.href)) {
|
|
576
|
+
const item = rec('link', el, { href: el.href });
|
|
577
|
+
if (item) result.links.push({ text: item.text, href: el.href, selector: item.selector });
|
|
578
|
+
}
|
|
579
|
+
if ((tag === 'INPUT' && el.type === 'checkbox') || role === 'checkbox') {
|
|
580
|
+
const item = rec('checkbox', el, { checked: !!el.checked });
|
|
581
|
+
if (item) result.checkboxes.push({ label: item.label || item.text, checked: !!el.checked });
|
|
582
|
+
}
|
|
583
|
+
if (isClickable(el) && !seenEl.has(el)) rec('hit', el);
|
|
584
|
+
const cls = String(el.className || '');
|
|
585
|
+
if (/load-?more/i.test(cls) || el.hasAttribute('data-infinite')) {
|
|
586
|
+
result.infiniteScroll = true;
|
|
587
|
+
rec('loadmore', el);
|
|
514
588
|
}
|
|
515
589
|
});
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
590
|
+
|
|
591
|
+
walk(document, (el) => {
|
|
592
|
+
if (el.tagName !== 'FORM') return;
|
|
519
593
|
result.forms.push({
|
|
520
594
|
action: el.action,
|
|
521
|
-
method: el.method,
|
|
595
|
+
method: (el.method || 'get').toLowerCase(),
|
|
522
596
|
inputs: Array.from(el.querySelectorAll('input, select, textarea')).map(i => ({
|
|
523
597
|
name: i.name,
|
|
524
598
|
type: i.type,
|
|
@@ -526,82 +600,54 @@ class SiteExplorer {
|
|
|
526
600
|
}))
|
|
527
601
|
});
|
|
528
602
|
});
|
|
529
|
-
|
|
530
|
-
// Tables
|
|
603
|
+
|
|
531
604
|
document.querySelectorAll('table, [role="grid"], [class*="table"]').forEach(el => {
|
|
532
605
|
const headers = Array.from(el.querySelectorAll('th, [role="columnheader"]')).map(h => h.textContent?.trim());
|
|
533
606
|
const rows = el.querySelectorAll('tr, [role="row"]').length;
|
|
534
607
|
result.tables.push({ headers, rowCount: rows });
|
|
535
608
|
});
|
|
536
|
-
|
|
537
|
-
// Pagination
|
|
609
|
+
|
|
538
610
|
const paginationEl = document.querySelector('[class*="pagination"], [role="navigation"][aria-label*="page"], .pager');
|
|
539
611
|
if (paginationEl) {
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
612
|
+
const pages = [];
|
|
613
|
+
paginationEl.querySelectorAll('a, button, [role="button"]').forEach((p) => {
|
|
614
|
+
const t = (p.textContent || '').trim();
|
|
615
|
+
pages.push(t);
|
|
616
|
+
const item = rec('pager', p, { text: t });
|
|
617
|
+
if (item) result.pagers.push(item);
|
|
618
|
+
});
|
|
619
|
+
result.pagination = { type: 'numbered', pages: pages.filter((t) => /\\d+/.test(t)) };
|
|
544
620
|
}
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
result.infiniteScroll = !!document.querySelector('[class*="infinite"], [data-infinite], [class*="load-more"]');
|
|
548
|
-
|
|
549
|
-
// Dropdowns
|
|
621
|
+
result.infiniteScroll = result.infiniteScroll || !!document.querySelector('[class*="infinite"], [data-infinite], [class*="load-more"]');
|
|
622
|
+
|
|
550
623
|
document.querySelectorAll('select, [role="listbox"], [role="combobox"], [class*="dropdown"], [class*="select"]').forEach(el => {
|
|
551
624
|
result.dropdowns.push({
|
|
552
625
|
text: el.textContent?.trim().slice(0, 30),
|
|
553
626
|
options: Array.from(el.querySelectorAll('option')).map(o => o.textContent?.trim()).slice(0, 10)
|
|
554
627
|
});
|
|
555
628
|
});
|
|
556
|
-
|
|
557
|
-
// Checkboxes
|
|
558
|
-
document.querySelectorAll('input[type="checkbox"], [role="checkbox"]').forEach(el => {
|
|
559
|
-
result.checkboxes.push({
|
|
560
|
-
label: el.labels?.[0]?.textContent?.trim() || el.getAttribute('aria-label'),
|
|
561
|
-
checked: el.checked
|
|
562
|
-
});
|
|
563
|
-
});
|
|
564
|
-
|
|
565
|
-
// Inputs
|
|
566
629
|
document.querySelectorAll('input[type="text"], input[type="search"], textarea').forEach(el => {
|
|
567
630
|
if (el.offsetParent !== null) {
|
|
568
|
-
result.inputs.push({
|
|
569
|
-
name: el.name,
|
|
570
|
-
placeholder: el.placeholder,
|
|
571
|
-
type: el.type
|
|
572
|
-
});
|
|
631
|
+
result.inputs.push({ name: el.name, placeholder: el.placeholder, type: el.type });
|
|
573
632
|
}
|
|
574
633
|
});
|
|
575
|
-
|
|
576
|
-
// Side panels / drawers
|
|
577
634
|
document.querySelectorAll('[class*="sidebar"], [class*="drawer"], [class*="panel"], aside').forEach(el => {
|
|
578
|
-
result.sidePanels.push({
|
|
579
|
-
visible: el.offsetParent !== null,
|
|
580
|
-
class: el.className
|
|
581
|
-
});
|
|
635
|
+
result.sidePanels.push({ visible: el.offsetParent !== null, class: el.className });
|
|
582
636
|
});
|
|
583
|
-
|
|
584
|
-
// Modals (hidden ones too)
|
|
585
637
|
document.querySelectorAll('[role="dialog"], .modal, [class*="modal"]').forEach(el => {
|
|
586
|
-
result.modals.push({
|
|
587
|
-
visible: el.offsetParent !== null || el.style.display !== 'none',
|
|
588
|
-
id: el.id
|
|
589
|
-
});
|
|
638
|
+
result.modals.push({ visible: el.offsetParent !== null || el.style.display !== 'none', id: el.id });
|
|
590
639
|
});
|
|
591
|
-
|
|
592
|
-
// Filters
|
|
593
640
|
document.querySelectorAll('[class*="filter"], [data-filter], [role="search"]').forEach(el => {
|
|
594
|
-
result.filters.push({
|
|
595
|
-
text: el.textContent?.trim().slice(0, 50)
|
|
596
|
-
});
|
|
641
|
+
result.filters.push({ text: el.textContent?.trim().slice(0, 50) });
|
|
597
642
|
});
|
|
598
643
|
|
|
599
644
|
return result;
|
|
600
645
|
} catch (e) {
|
|
601
646
|
return {
|
|
602
647
|
tabs: [], buttons: [], links: [], forms: [], tables: [], modals: [],
|
|
603
|
-
filters: [], pagination: null, infiniteScroll: false, sidePanels: [],
|
|
604
|
-
dropdowns: [], checkboxes: [], inputs: [],
|
|
648
|
+
filters: [], pagination: null, pagers: [], infiniteScroll: false, sidePanels: [],
|
|
649
|
+
dropdowns: [], checkboxes: [], inputs: [], clickables: [],
|
|
650
|
+
discoveryError: String(e && e.message || e)
|
|
605
651
|
};
|
|
606
652
|
}
|
|
607
653
|
})()
|
|
@@ -669,12 +715,22 @@ class SiteExplorer {
|
|
|
669
715
|
}
|
|
670
716
|
|
|
671
717
|
sameOrigin(url) {
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
718
|
+
return sameOriginUrl(url, this.startOrigin, this.startHref);
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
harvestFrontier(els, sid, harFrom) {
|
|
722
|
+
const enqueue = this._enqueue;
|
|
723
|
+
if (!enqueue) return;
|
|
724
|
+
const loc = (els && els.locationHref) || null;
|
|
725
|
+
if (loc) enqueue(loc);
|
|
726
|
+
for (const link of (els && els.links) || []) {
|
|
727
|
+
if (link && link.href) enqueue(link.href);
|
|
728
|
+
}
|
|
729
|
+
for (const form of (els && els.forms) || []) {
|
|
730
|
+
const method = String((form && form.method) || 'get').toLowerCase();
|
|
731
|
+
if (method === 'get' && form.action) enqueue(form.action);
|
|
677
732
|
}
|
|
733
|
+
for (const url of harDocumentUrls(this.requests, harFrom)) enqueue(url);
|
|
678
734
|
}
|
|
679
735
|
|
|
680
736
|
async enableNavGuard(sid) {
|
|
@@ -733,42 +789,66 @@ class SiteExplorer {
|
|
|
733
789
|
const poison = /delete|remove|sign out|log out|logout|disconnect|unsubscribe/;
|
|
734
790
|
const flayKey = (kind, item) => `${kind}|${(item.text || item.label || '').trim().slice(0, 80)}|${item.selector || ''}`;
|
|
735
791
|
const unsafe = (item) => poison.test((item.text || item.label || '').toLowerCase());
|
|
736
|
-
let
|
|
737
|
-
|
|
792
|
+
let emptyFlays = 0;
|
|
793
|
+
let lastHar = this.requests.length;
|
|
794
|
+
let didInfinite = false;
|
|
795
|
+
while (true) {
|
|
796
|
+
const harFrom = this.requests.length;
|
|
738
797
|
let els;
|
|
739
798
|
try { els = await this.discoverElements(sid); }
|
|
740
799
|
catch (e) {
|
|
741
800
|
console.error(`[explore] rediscover failed (${e.message})`);
|
|
742
|
-
els = { tabs: [], buttons: [], checkboxes: [] };
|
|
801
|
+
els = { tabs: [], buttons: [], checkboxes: [], clickables: [], pagers: [], links: [], forms: [] };
|
|
743
802
|
}
|
|
744
803
|
const queue = [];
|
|
745
|
-
|
|
746
|
-
for (const
|
|
747
|
-
for (const
|
|
748
|
-
const
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
804
|
+
const pushQ = (kind, item) => { if (item) queue.push({ kind, item }); };
|
|
805
|
+
for (const c of els.clickables || []) pushQ(c.kind || 'hit', c);
|
|
806
|
+
for (const tab of els.tabs || []) pushQ('tab', tab);
|
|
807
|
+
for (const btn of els.buttons || []) pushQ('button', btn);
|
|
808
|
+
for (const cb of els.checkboxes || []) pushQ('checkbox', cb);
|
|
809
|
+
for (const pg of els.pagers || []) pushQ('pager', pg);
|
|
810
|
+
const next = queue.find(({ kind, item }) => !unsafe(item) && !visited.has(flayKey(kind, item)) && (item.text || item.label || item.selector));
|
|
811
|
+
if (next) {
|
|
812
|
+
emptyFlays = 0;
|
|
813
|
+
visited.add(flayKey(next.kind, next.item));
|
|
814
|
+
try {
|
|
815
|
+
if (next.kind === 'checkbox' && next.item.label) {
|
|
816
|
+
await this.evaluate(`
|
|
817
|
+
const cb = Array.from(document.querySelectorAll('input[type="checkbox"]'))
|
|
818
|
+
.find(e => e.labels?.[0]?.textContent?.includes(${JSON.stringify(next.item.label)}));
|
|
819
|
+
if (cb) cb.click();
|
|
820
|
+
`, sid);
|
|
821
|
+
} else if (next.item.selector) {
|
|
822
|
+
await this.clickElement(next.item.selector, sid);
|
|
823
|
+
} else if (next.item.text) {
|
|
824
|
+
await this.clickByText(next.item.text, sid);
|
|
825
|
+
}
|
|
826
|
+
this.clicksPerformed++;
|
|
827
|
+
await this.settleDom(sid);
|
|
828
|
+
try {
|
|
829
|
+
els.locationHref = await this.evaluate('window.location.href', sid);
|
|
830
|
+
} catch (_) {}
|
|
831
|
+
this.harvestFrontier(els, sid, harFrom);
|
|
832
|
+
lastHar = this.requests.length;
|
|
833
|
+
} catch (e) {
|
|
834
|
+
console.error(`[explore] flay widget failed: ${e.message}`);
|
|
835
|
+
}
|
|
752
836
|
continue;
|
|
753
837
|
}
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
const cb = Array.from(document.querySelectorAll('input[type="checkbox"]'))
|
|
760
|
-
.find(e => e.labels?.[0]?.textContent?.includes(${JSON.stringify(next.item.label)}));
|
|
761
|
-
if (cb) cb.click();
|
|
762
|
-
`, sid);
|
|
763
|
-
} else if (next.item.selector) {
|
|
764
|
-
await this.clickElement(next.item.selector, sid);
|
|
765
|
-
} else if (next.item.text) {
|
|
766
|
-
await this.clickByText(next.item.text, sid);
|
|
767
|
-
}
|
|
768
|
-
this.clicksPerformed++;
|
|
769
|
-
} catch (e) {
|
|
770
|
-
console.error(`[explore] flay widget failed: ${e.message}`);
|
|
838
|
+
if (els.infiniteScroll && !didInfinite) {
|
|
839
|
+
didInfinite = true;
|
|
840
|
+
emptyFlays = 0;
|
|
841
|
+
await this.scrollToBottom(sid);
|
|
842
|
+
continue;
|
|
771
843
|
}
|
|
844
|
+
if (harDocumentUrls(this.requests, lastHar).length) {
|
|
845
|
+
this.harvestFrontier(els, sid, lastHar);
|
|
846
|
+
lastHar = this.requests.length;
|
|
847
|
+
emptyFlays = 0;
|
|
848
|
+
continue;
|
|
849
|
+
}
|
|
850
|
+
emptyFlays += 1;
|
|
851
|
+
if (emptyFlays >= 2) break;
|
|
772
852
|
}
|
|
773
853
|
}
|
|
774
854
|
|
|
@@ -776,15 +856,15 @@ class SiteExplorer {
|
|
|
776
856
|
while (true) {
|
|
777
857
|
const url = await q.pop();
|
|
778
858
|
if (url == null) return;
|
|
859
|
+
const harFrom = this.requests.length;
|
|
779
860
|
try {
|
|
780
861
|
console.error(`[explore] hydra ${sid} ${url} q=${q.q.length} active=${q.active}`);
|
|
781
862
|
await this.evaluate(`location.assign(${JSON.stringify(url)})`, sid);
|
|
782
863
|
await this.settleDom(sid);
|
|
783
864
|
if (this.depth !== 0) await this.flayWidgets(sid);
|
|
784
865
|
const els = await this.discoverElements(sid);
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
}
|
|
866
|
+
try { els.locationHref = await this.evaluate('window.location.href', sid); } catch (_) {}
|
|
867
|
+
this.harvestFrontier(els, sid, harFrom);
|
|
788
868
|
if (doShot && this.clicksPerformed % 5 === 0) {
|
|
789
869
|
try { await this.screenshot(`flay-${this.clicksPerformed}`, sid); } catch (_) {}
|
|
790
870
|
}
|
|
@@ -835,7 +915,7 @@ class SiteExplorer {
|
|
|
835
915
|
}
|
|
836
916
|
} catch (e) {
|
|
837
917
|
console.error(`[explore] DOM discovery failed (${e.message}); skipping discovery, preserving HAR`);
|
|
838
|
-
elements = { tabs: [], buttons: [], links: [], forms: [], tables: [], dropdowns: [], checkboxes: [], modals: [], sidePanels: [] };
|
|
918
|
+
elements = { tabs: [], buttons: [], links: [], forms: [], tables: [], dropdowns: [], checkboxes: [], modals: [], sidePanels: [], clickables: [], pagers: [] };
|
|
839
919
|
this.siteMap.discoveryError = e.message;
|
|
840
920
|
}
|
|
841
921
|
|
|
@@ -844,18 +924,15 @@ class SiteExplorer {
|
|
|
844
924
|
} else {
|
|
845
925
|
const q = new WorkQueue();
|
|
846
926
|
const seen = new Set();
|
|
847
|
-
const enqueue = (
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
this.templateHits.set(tmpl, (this.templateHits.get(tmpl) || 0) + 1);
|
|
857
|
-
q.push(norm);
|
|
858
|
-
};
|
|
927
|
+
const enqueue = createEnqueue({
|
|
928
|
+
startOrigin: this.startOrigin,
|
|
929
|
+
startHref: this.startHref,
|
|
930
|
+
templateHits: this.templateHits,
|
|
931
|
+
cap: PATH_TEMPLATE_CAP,
|
|
932
|
+
seen,
|
|
933
|
+
push: (norm) => q.push(norm)
|
|
934
|
+
});
|
|
935
|
+
this._enqueue = enqueue;
|
|
859
936
|
enqueue(this.startHref);
|
|
860
937
|
const sessions = [this.sessionId];
|
|
861
938
|
for (let i = 1; i < this.workers; i++) {
|
|
@@ -907,6 +984,7 @@ class SiteExplorer {
|
|
|
907
984
|
structure: {
|
|
908
985
|
tabs: this.siteMap.tabs.length,
|
|
909
986
|
buttons: this.siteMap.buttons.length,
|
|
987
|
+
clickables: (this.siteMap.clickables || []).length,
|
|
910
988
|
links: this.siteMap.links.length,
|
|
911
989
|
forms: this.siteMap.forms.length,
|
|
912
990
|
tables: this.siteMap.tables.length,
|
|
@@ -1234,7 +1312,15 @@ Examples:
|
|
|
1234
1312
|
}
|
|
1235
1313
|
}
|
|
1236
1314
|
|
|
1237
|
-
module.exports = {
|
|
1315
|
+
module.exports = {
|
|
1316
|
+
SiteExplorer,
|
|
1317
|
+
pathTemplate,
|
|
1318
|
+
PATH_TEMPLATE_CAP,
|
|
1319
|
+
HYDRA_WIDTH,
|
|
1320
|
+
sameOriginUrl,
|
|
1321
|
+
createEnqueue,
|
|
1322
|
+
harDocumentUrls
|
|
1323
|
+
};
|
|
1238
1324
|
|
|
1239
1325
|
if (require.main === module) {
|
|
1240
1326
|
main();
|
package/lib/browser-config.js
CHANGED
|
@@ -85,7 +85,7 @@ function loadBrowserConfig(options = {}) {
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
function isBrowserInternalUrl(url) {
|
|
88
|
-
return /^(?:about|arc|brave|chrome|chrome-extension|edge|opera|vivaldi):/i.test(String(url || ''));
|
|
88
|
+
return /^(?:about|arc|brave|chrome|chrome-extension|edge|helium|opera|vivaldi):/i.test(String(url || ''));
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
module.exports = {
|