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

- move auto-play, auto-fetch and auto-scroll behaviors to behaviors/global/* - bgbehaviors manages these background behaviors - command line --bgbehaviors option specifies which background behaviors to run (defaults to auto-fetch and auto-play)
44 lines
1.1 KiB
JavaScript
44 lines
1.1 KiB
JavaScript
const AutoPlayBehavior = require("./global/autoplay");
|
|
|
|
const AutoFetchBehavior = require("./global/autofetcher");
|
|
|
|
const AutoScrollBehavior = require("./global/autoscroll");
|
|
|
|
|
|
// ===========================================================================
|
|
class BackgroundBehaviors
|
|
{
|
|
constructor(bgbehaviors) {
|
|
this.doAutoFetch = bgbehaviors.includes("auto-fetch");
|
|
this.doAutoPlay = bgbehaviors.includes("auto-play");
|
|
this.doAutoScroll = bgbehaviors.includes("auto-scroll");
|
|
}
|
|
|
|
async setup(page, crawler) {
|
|
const behaviors = [];
|
|
|
|
try {
|
|
if (this.doAutoFetch) {
|
|
behaviors.push(new AutoFetchBehavior());
|
|
}
|
|
|
|
if (this.doAutoPlay) {
|
|
behaviors.push(new AutoPlayBehavior());
|
|
}
|
|
|
|
if (this.doAutoScroll) {
|
|
behaviors.push(new AutoScrollBehavior());
|
|
}
|
|
|
|
await Promise.all(behaviors.map(b => b.beforeLoad(page, crawler)));
|
|
|
|
} catch (err) {
|
|
console.log(err);
|
|
}
|
|
|
|
return () => Promise.all(behaviors.map(b => b.afterLoad(page, crawler)));
|
|
}
|
|
}
|
|
|
|
module.exports = BackgroundBehaviors;
|
|
|