feat: add change_viewport option

This commit is contained in:
2025-04-13 00:43:55 +07:00
parent 50c5927be7
commit 358fe53be9
3 changed files with 13 additions and 7 deletions

View File

@ -3,14 +3,17 @@ import logger from "../logger";
import * as twitch from "../website/twitch";
import * as constants from "../constants";
async function spawn(context: BrowserContext, targetUrl: string, spawnId: string = "unknown") {
async function spawn(context: BrowserContext, targetUrl: string, changeViewport: boolean = false, spawnId: string = "unknown") {
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();
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);
if (changeViewport) {
logger.debug(`[${spawnId}] Changing viewport size...`);
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) {