UNPKG

@labnex/cli

Version:

CLI for Labnex, an AI-Powered Testing Automation Platform

48 lines 2.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.handleScroll = handleScroll; const elementFinderV2_1 = require("../elementFinderV2"); // Updated import async function handleScroll(page, // Included for consistency, though currentFrame is primary currentFrame, addLog, target, originalStep, retryApiCallFn // Added ) { if (!page) throw new Error('Page not available for scroll'); if (!currentFrame) throw new Error('Current frame not available for scroll'); const executionContext = currentFrame; if (!target) { addLog('No scroll target specified, scrolling current context window down by a bit.'); await executionContext.evaluate(() => window.scrollBy(0, window.innerHeight / 2)); return; } addLog(`Attempting to scroll with target: "${target}" in current context`); let elementToScrollTo = null; try { // Try to find the element if a target is specified // Pass page and currentFrame to findElementWithFallbacks, even if page is not directly used by this handler's logic after element finding elementToScrollTo = await (0, elementFinderV2_1.findElementWithFallbacks)(page, currentFrame, addLog, target, target, originalStep, false, retryApiCallFn); if (elementToScrollTo) { addLog('Element found, scrolling it into view.'); await elementToScrollTo.evaluate(el => el.scrollIntoView({ behavior: 'smooth', block: 'center' })); // Add a small delay to allow smooth scroll to finish and content to settle. await new Promise(resolve => setTimeout(resolve, 500)); addLog('Successfully scrolled to element.'); } else { // This case should ideally be handled by findElementWithFallbacks throwing an error addLog('Scroll target element not found, attempting generic page scroll as fallback.'); await executionContext.evaluate(() => window.scrollBy(0, window.innerHeight / 2)); } } catch (error) { addLog(`Error scrolling to target "${target}": ${error.message}. Attempting generic page scroll.`); // Fallback to generic scroll if specific element scroll fails await executionContext.evaluate(() => window.scrollBy(0, window.innerHeight / 2)); } finally { if (elementToScrollTo) { await elementToScrollTo.dispose(); } } } //# sourceMappingURL=handleScroll.js.map