browsertrix-crawler/behaviors/global/autoscroll.js
Emma Dickson 0688674f6f
case insensitive params (#27)
* make --generateWacz, --generateCdx case insensitive with alias option
* fix eslint config and eslint issues

Co-authored-by: Emma Dickson <emmadickson@Emmas-MacBook-Pro.local>
Co-authored-by: Ilya Kreymer <ikreymer@gmail.com>
2021-02-17 09:37:07 -08:00

37 lines
915 B
JavaScript

async function autoScroll() {
const canScrollMore = () =>
self.scrollY + self.innerHeight <
Math.max(
self.document.body.scrollHeight,
self.document.body.offsetHeight,
self.document.documentElement.clientHeight,
self.document.documentElement.scrollHeight,
self.document.documentElement.offsetHeight
);
const scrollOpts = { top: 250, left: 0, behavior: "auto" };
while (canScrollMore()) {
self.scrollBy(scrollOpts);
await new Promise(resolve => setTimeout(resolve, 500));
}
}
// ===========================================================================
class AutoScrollBehavior
{
async beforeLoad() {
}
async afterLoad(page, crawler) {
try {
await Promise.race([page.evaluate(autoScroll), crawler.sleep(30000)]);
} catch (e) {
console.warn("Autoscroll Behavior Failed", e);
}
}
}
module.exports = AutoScrollBehavior;