UNPKG

@applitools/eyes-playwright

Version:
34 lines (33 loc) 1.04 kB
"use strict"; /** * Scroll Preserver - Utility to preserve and restore scroll positions * * When window.onload() is triggered, React re-renders and may scroll to top. * This utility captures scroll positions before the re-render and restores them after. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.ScrollPreserver = void 0; class ScrollPreserver { constructor() { this.savedScrollPosition = null; } /** * Capture the current scroll position of the window */ captureScrollPosition() { this.savedScrollPosition = { x: window.scrollX || window.pageXOffset, y: window.scrollY || window.pageYOffset, }; } /** * Restore the previously captured scroll position */ restoreScrollPosition() { if (this.savedScrollPosition) { window.scrollTo(this.savedScrollPosition.x, this.savedScrollPosition.y); this.savedScrollPosition = null; } } } exports.ScrollPreserver = ScrollPreserver;