mirror of
https://github.com/webrecorder/browsertrix-crawler.git
synced 2025-10-19 14:33:17 +00:00

* 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>
37 lines
915 B
JavaScript
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;
|