feat: add channel open interval configuration and improve page navigation logic

This commit is contained in:
duanshuwen
2026-04-15 22:08:54 +08:00
parent e77c815a86
commit 5a8e5e4ac2
3 changed files with 21 additions and 3 deletions

View File

@@ -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);
}
}