MCPcopy
hub / github.com/DO-SAY-GO/dn / indexURL

Function indexURL

src/archivist.js:481–652  ·  view source on GitHub ↗
({targetInfo:info = {}, sessionId, waitingForDebugger} = {})

Source from the content-addressed store, hash-verified

479 }
480
481 async function indexURL({targetInfo:info = {}, sessionId, waitingForDebugger} = {}) {
482 if ( waitingForDebugger ) {
483 console.warn(info);
484 throw new TypeError(`Target not ready for install`);
485 }
486 if ( Mode == 'serve' ) return;
487 if ( info.type != 'page' ) return;
488 if ( ! info.url || info.url == 'about:blank' ) return;
489 if ( info.url.startsWith('chrome') ) return;
490 if ( dontCache(info) ) return;
491
492 DEBUG.verboseSlow && console.log('Index URL', info);
493
494 DEBUG.verboseSlow && console.log('Index URL called', info);
495
496 if ( State.Indexing.has(info.targetId) ) return;
497 State.Indexing.add(info.targetId);
498
499 if ( ! sessionId ) {
500 sessionId = await untilHas(
501 State.Sessions, info.targetId,
502 {timeout: State.crawling && State.crawlTimeout}
503 );
504 }
505
506 if ( !State.Installations.has(sessionId) ) {
507 await untilHas(
508 State.Installations, sessionId,
509 {timeout: State.crawling && State.crawlTimeout}
510 );
511 }
512
513 send("DOMSnapshot.enable", {}, sessionId);
514
515 await sleep(500);
516
517 const flatDoc = await send("DOMSnapshot.captureSnapshot", {
518 computedStyles: [],
519 }, sessionId);
520 const pageText = processDoc(flatDoc).replace(STRIP_CHARS, ' ');
521
522 if ( State.crawling ) {
523 const has = await untilTrue(() => State.CrawlData.has(info.targetId));
524
525 const {url} = Targets.get(sessionId);
526 if ( ! dontCache({url}) ) {
527 if ( has ) {
528 const {depth,links} = State.CrawlData.get(info.targetId);
529 DEBUG.verboseSlow && console.log(info, {depth,links});
530
531 const {result:{value:{title,links:crawlLinks}}} = await send("Runtime.evaluate", {
532 expression: `(function () {
533 return {
534 links: Array.from(
535 document.querySelectorAll('a[href]')
536 ).map(a => a.href),
537 title: document.title
538 };

Callers 2

reindexOnContentChangeFunction · 0.85
installForSessionFunction · 0.85

Calls 8

sleepFunction · 0.90
untilTrueFunction · 0.90
dontCacheFunction · 0.85
untilHasFunction · 0.85
sendFunction · 0.85
processDocFunction · 0.85
toNDXDocFunction · 0.85
getContentSigFunction · 0.85

Tested by

no test coverage detected