fix: check consent button every second
This commit is contained in:
@ -36,8 +36,7 @@ async function spawn(context: BrowserContext, targetUrl: string, spawnId: string
|
||||
await page.waitForTimeout(15000); // Wait for 15 second to let the page load
|
||||
// Keep-alive the page open for 5 minutes then refresh
|
||||
if (targetUrl.startsWith("https://www.twitch.tv/")) {
|
||||
logger.info(`[${spawnId}] Twitch URL detected, initializing...`);
|
||||
await twitch.init(page, spawnId);
|
||||
logger.info(`[${spawnId}] Twitch URL detected, using Twitch mode...`);
|
||||
await twitch.keepAlive(page, spawnId);
|
||||
} else {
|
||||
logger.warn(`[${spawnId}] Unsupported URL: ${targetUrl}`);
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import type { Page } from "patchright";
|
||||
import logger from "../logger";
|
||||
|
||||
async function init(page: Page, spawnId: string = "unknown") {
|
||||
async function checkConsentButton(page: Page, spawnId: string = "unknown") {
|
||||
const consentButton = page.locator("button[data-a-target='consent-banner-accept']");
|
||||
if ((await consentButton.all()).length > 0) {
|
||||
logger.debug(`[${spawnId}] Consent button found, clicking it...`);
|
||||
@ -21,7 +21,10 @@ async function keepAlive(page: Page, spawnId: string = "unknown") {
|
||||
if ((await page.locator(".ScCoreButton-sc-ocjdkq-0.ggPgVz").all()).length > 0) {
|
||||
logger.debug(`[${spawnId}] Player encountered an error, refreshing the page...`);
|
||||
await page.reload({timeout: 0, waitUntil: "domcontentloaded"});
|
||||
waitTime = 0;
|
||||
continue;
|
||||
}
|
||||
await checkConsentButton(page, spawnId);
|
||||
if (waitTime > 5 * 60 * 1000) {
|
||||
logger.debug(`[${spawnId}] Waited for more than 5 minutes, refreshing the page...`);
|
||||
await page.reload({timeout: 0, waitUntil: "domcontentloaded"});
|
||||
@ -33,4 +36,4 @@ async function keepAlive(page: Page, spawnId: string = "unknown") {
|
||||
}
|
||||
}
|
||||
|
||||
export { init, keepAlive };
|
||||
export { keepAlive };
|
||||
|
||||
Reference in New Issue
Block a user