feat: add change_viewport option
This commit is contained in:
@ -1,11 +1,13 @@
|
|||||||
class Config {
|
class Config {
|
||||||
playwright: {
|
playwright: {
|
||||||
browser: string;
|
browser: string;
|
||||||
|
change_viewport: boolean;
|
||||||
headless: boolean;
|
headless: boolean;
|
||||||
cdp: string;
|
cdp: string;
|
||||||
url: string;
|
url: string;
|
||||||
} = {
|
} = {
|
||||||
browser: "chromium",
|
browser: "chromium",
|
||||||
|
change_viewport: true,
|
||||||
headless: true,
|
headless: true,
|
||||||
cdp: "ws://127.0.0.1:9222",
|
cdp: "ws://127.0.0.1:9222",
|
||||||
url: "https://www.twitch.tv/",
|
url: "https://www.twitch.tv/",
|
||||||
|
|||||||
@ -16,9 +16,10 @@ if (fs.existsSync("config.json")) {
|
|||||||
config = Config.fromJSON(text);
|
config = Config.fromJSON(text);
|
||||||
} else {
|
} else {
|
||||||
logger.info("No configuration file found. Using the default configuration.");
|
logger.info("No configuration file found. Using the default configuration.");
|
||||||
await fs.promises.writeFile("config.json", config.toJSON());
|
|
||||||
logger.info("Default configuration file 'config.json' created.");
|
logger.info("Default configuration file 'config.json' created.");
|
||||||
}
|
}
|
||||||
|
// Write the new config file in case we updated something.
|
||||||
|
await fs.promises.writeFile("config.json", config.toJSON());
|
||||||
|
|
||||||
logger.level = process.env.LOG_LEVEL || config.logger.level;
|
logger.level = process.env.LOG_LEVEL || config.logger.level;
|
||||||
logger.info(`Logger level set to '${logger.level}'`);
|
logger.info(`Logger level set to '${logger.level}'`);
|
||||||
@ -63,7 +64,7 @@ if (config.proxy.mode === "reflect4") {
|
|||||||
const spawnId = `${i + 1}`;
|
const spawnId = `${i + 1}`;
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
await reflect4.spawn(context, config.playwright.url, spawnId);
|
await reflect4.spawn(context, config.playwright.url, config.playwright.change_viewport, spawnId);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.error(`[${spawnId}] Error while running: ${e}`);
|
logger.error(`[${spawnId}] Error while running: ${e}`);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,14 +3,17 @@ import logger from "../logger";
|
|||||||
import * as twitch from "../website/twitch";
|
import * as twitch from "../website/twitch";
|
||||||
import * as constants from "../constants";
|
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)];
|
const server = constants.REFLECT4_SERVERS[Math.floor(Math.random() * constants.REFLECT4_SERVERS.length)];
|
||||||
logger.debug(`[${spawnId}] Using reflect4 server: ${server}`);
|
logger.debug(`[${spawnId}] Using reflect4 server: ${server}`);
|
||||||
const page = await context.newPage();
|
const page = await context.newPage();
|
||||||
const deviceName = Object.keys(devices)[Math.floor(Math.random() * Object.keys(devices).length)];
|
if (changeViewport) {
|
||||||
const device = devices[deviceName];
|
logger.debug(`[${spawnId}] Changing viewport size...`);
|
||||||
logger.debug(`[${spawnId}] Using device: ${deviceName}`);
|
const deviceName = Object.keys(devices)[Math.floor(Math.random() * Object.keys(devices).length)];
|
||||||
await page.setViewportSize(device.viewport);
|
const device = devices[deviceName];
|
||||||
|
logger.debug(`[${spawnId}] Using device: ${deviceName}`);
|
||||||
|
await page.setViewportSize(device.viewport);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
await page.goto(server);
|
await page.goto(server);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user