From 50c5927be71161f87d5be7298a130d8703bc7287 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=E1=BA=BF=20H=C6=B0ng?= Date: Sun, 13 Apr 2025 00:34:57 +0700 Subject: [PATCH] fix: check consent button every second --- src/proxy/reflect4.ts | 3 +-- src/website/twitch.ts | 7 +++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/proxy/reflect4.ts b/src/proxy/reflect4.ts index f838892..8cd42d5 100644 --- a/src/proxy/reflect4.ts +++ b/src/proxy/reflect4.ts @@ -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}`); diff --git a/src/website/twitch.ts b/src/website/twitch.ts index 05071e4..dd00082 100644 --- a/src/website/twitch.ts +++ b/src/website/twitch.ts @@ -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 };