feat: add channel open interval configuration and improve page navigation logic
This commit is contained in:
@@ -43,6 +43,15 @@ const isBlankLikePage = (url) => {
|
||||
return false;
|
||||
};
|
||||
|
||||
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
|
||||
const getOpenInterval = () => {
|
||||
const raw = process.env.CHANNEL_OPEN_INTERVAL_MS;
|
||||
if (!raw) return 5000;
|
||||
const n = Number(raw);
|
||||
return Number.isFinite(n) && n >= 0 ? n : 5000;
|
||||
};
|
||||
|
||||
(async () => {
|
||||
let browser;
|
||||
|
||||
@@ -66,6 +75,7 @@ const isBlankLikePage = (url) => {
|
||||
});
|
||||
|
||||
const usedPages = new Set();
|
||||
const openInterval = getOpenInterval();
|
||||
|
||||
for (let i = 0; i < channels.length; i++) {
|
||||
const targetUrl = channels[i]?.channelUrl;
|
||||
@@ -103,7 +113,12 @@ const isBlankLikePage = (url) => {
|
||||
const current = page.url();
|
||||
|
||||
if (!current || !isSameTarget(current, targetUrl)) {
|
||||
await page.goto(targetUrl, { waitUntil: 'domcontentloaded' });
|
||||
await page.goto(targetUrl, { waitUntil: 'networkidle' });
|
||||
}
|
||||
|
||||
if (i < channels.length - 1 && openInterval > 0) {
|
||||
log.info(`Channel ${i + 1}/${channels.length} opened. Sleeping ${openInterval}ms before next...`);
|
||||
await sleep(openInterval);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user