@applitools/eyes-playwright
Version:
Applitools Eyes SDK for Playwright
34 lines (33 loc) • 1.04 kB
JavaScript
;
/**
* 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;