feat: random device resolution & accept cookies
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import { type BrowserContext, type Locator } from "patchright";
|
||||
import { devices, type BrowserContext, type Locator } from "patchright";
|
||||
import logger from "../logger";
|
||||
import * as twitch from "../website/twitch";
|
||||
import * as constants from "../constants";
|
||||
@ -7,7 +7,10 @@ async function spawn(context: BrowserContext, targetUrl: string, spawnId: string
|
||||
const server = constants.REFLECT4_SERVERS[Math.floor(Math.random() * constants.REFLECT4_SERVERS.length)];
|
||||
logger.debug(`[${spawnId}] Using reflect4 server: ${server}`);
|
||||
const page = await context.newPage();
|
||||
await page.setViewportSize({width: 640, height: 360});
|
||||
const deviceName = Object.keys(devices)[Math.floor(Math.random() * Object.keys(devices).length)];
|
||||
const device = devices[deviceName];
|
||||
logger.debug(`[${spawnId}] Using device: ${deviceName}`);
|
||||
await page.setViewportSize(device.viewport);
|
||||
try {
|
||||
await page.goto(server);
|
||||
} catch (e) {
|
||||
@ -33,6 +36,8 @@ 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);
|
||||
await twitch.keepAlive(page, spawnId);
|
||||
} else {
|
||||
logger.warn(`[${spawnId}] Unsupported URL: ${targetUrl}`);
|
||||
|
||||
Reference in New Issue
Block a user