(page, exclusions = READABILITY_EXCLUSIONS)
| 599 | * zu unterscheiden, und ist stabil ueber die Halte hinweg. |
| 600 | */ |
| 601 | export async function scrollRegionsToEnd(page, exclusions = READABILITY_EXCLUSIONS) { |
| 602 | return page.evaluate((selectors) => { |
| 603 | const excluded = (node) => selectors.some((selector) => node.closest(selector) !== null); |
| 604 | const identify = (node) => { |
| 605 | const testId = node.getAttribute('data-testid'); |
| 606 | if (testId !== null && testId.length > 0) { |
| 607 | return testId; |
| 608 | } |
| 609 | const classes = (node.getAttribute('class') ?? '').split(/\s+/).filter(Boolean); |
| 610 | return classes.length > 0 ? classes[0] : node.tagName.toLowerCase(); |
| 611 | }; |
| 612 | const scrolled = []; |
| 613 | for (const node of document.body.querySelectorAll('*')) { |
| 614 | if (excluded(node)) { |
| 615 | continue; |
| 616 | } |
| 617 | const rect = node.getBoundingClientRect(); |
| 618 | if (rect.width <= 0 || rect.height <= 0) { |
| 619 | continue; |
| 620 | } |
| 621 | const style = window.getComputedStyle(node); |
| 622 | const scrollableY = (style.overflowY === 'auto' || style.overflowY === 'scroll') |
| 623 | && node.scrollHeight > node.clientHeight + 1; |
| 624 | const scrollableX = (style.overflowX === 'auto' || style.overflowX === 'scroll') |
| 625 | && node.scrollWidth > node.clientWidth + 1; |
| 626 | if (!scrollableY && !scrollableX) { |
| 627 | continue; |
| 628 | } |
| 629 | const before = { top: node.scrollTop, left: node.scrollLeft }; |
| 630 | if (scrollableY) { |
| 631 | node.scrollTop = node.scrollHeight; |
| 632 | } |
| 633 | if (scrollableX) { |
| 634 | node.scrollLeft = node.scrollWidth; |
| 635 | } |
| 636 | scrolled.push({ |
| 637 | name: identify(node), |
| 638 | axis: scrollableY && scrollableX ? 'both' : scrollableY ? 'y' : 'x', |
| 639 | before, |
| 640 | after: { top: node.scrollTop, left: node.scrollLeft }, |
| 641 | scrollHeight: node.scrollHeight, |
| 642 | clientHeight: node.clientHeight, |
| 643 | scrollWidth: node.scrollWidth, |
| 644 | clientWidth: node.clientWidth, |
| 645 | }); |
| 646 | } |
| 647 | return scrolled; |
| 648 | }, exclusions.map((entry) => entry.selector)); |
| 649 | } |
| 650 | |
| 651 | /** |
| 652 | * Alle Bereiche wieder an den Anfang, damit der naechste Schritt oben beginnt. |
no test coverage detected