From b3bf92c2d9b140e08cf0a4c24dcf2a83c7481993 Mon Sep 17 00:00:00 2001 From: Ralf Vogler Date: Tue, 27 May 2025 00:05:13 +0200 Subject: [PATCH] use patchright in unrealengine and steam-games (both stale) --- steam-games.js | 34 +++++++++++----------------------- unrealengine.js | 19 ++++++++++--------- 2 files changed, 21 insertions(+), 32 deletions(-) diff --git a/steam-games.js b/steam-games.js index ed54253..4acb4f0 100644 --- a/steam-games.js +++ b/steam-games.js @@ -1,36 +1,24 @@ -import { firefox } from 'playwright-firefox'; // stealth plugin needs no outdated playwright-extra -import { jsonDb, prompt } from './src/util.js'; +// import { firefox } from 'playwright-firefox'; +import { chromium } from 'patchright'; +import { datetime, filenamify, jsonDb, prompt } from './src/util.js'; import { cfg } from './src/config.js'; const db = await jsonDb('steam-games.json', {}); const user = cfg.steam_id || await prompt({ message: 'Enter Steam community id ("View my profile", then copy from URL)' }); -// using https://github.com/apify/fingerprint-suite worked, but has no launchPersistentContext... -// from https://github.com/apify/fingerprint-suite/issues/162 -import { FingerprintInjector } from 'fingerprint-injector'; -import { FingerprintGenerator } from 'fingerprint-generator'; - -const { fingerprint, headers } = new FingerprintGenerator().getFingerprint({ - devices: ['desktop'], - operatingSystems: ['windows'], -}); - -const context = await firefox.launchPersistentContext(cfg.dir.browser, { +const context = await chromium.launchPersistentContext(cfg.dir.browser, { headless: cfg.headless, // viewport: { width: cfg.width, height: cfg.height }, locale: 'en-US', // ignore OS locale to be sure to have english text for locators -> done via /en in URL - userAgent: fingerprint.navigator.userAgent, - viewport: { - width: fingerprint.screen.width, - height: fingerprint.screen.height, - }, - extraHTTPHeaders: { - 'accept-language': headers['accept-language'], - }, + recordVideo: cfg.record ? { dir: 'data/record/', size: { width: cfg.width, height: cfg.height } } : undefined, // will record a .webm video for each page navigated; without size, video would be scaled down to fit 800x800 + recordHar: cfg.record ? { path: `data/record/steam-${filenamify(datetime())}.har` } : undefined, // will record a HAR file with network requests and responses; can be imported in Chrome devtools + handleSIGINT: false, // have to handle ourselves and call context.close(), otherwise recordings from above won't be saved + // https://peter.sh/experiments/chromium-command-line-switches/ + args: [ + '--hide-crash-restore-bubble', + ], }); -// await stealth(context); -await new FingerprintInjector().attachFingerprintToPlaywright(context, { fingerprint, headers }); context.setDefaultTimeout(cfg.debug ? 0 : cfg.timeout); diff --git a/unrealengine.js b/unrealengine.js index 2bb8ee9..4fee9ec 100644 --- a/unrealengine.js +++ b/unrealengine.js @@ -1,11 +1,12 @@ // TODO This is mostly a copy of epic-games.js // New assets to claim every first Tuesday of a month. -import { firefox } from 'playwright-firefox'; // stealth plugin needs no outdated playwright-extra +// import { firefox } from 'playwright-firefox'; +import { chromium } from 'patchright'; import { authenticator } from 'otplib'; import path from 'path'; import { writeFileSync } from 'fs'; -import { resolve, jsonDb, datetime, stealth, filenamify, prompt, notify, html_game_list, handleSIGINT } from './src/util.js'; +import { resolve, jsonDb, datetime, filenamify, prompt, notify, html_game_list, handleSIGINT } from './src/util.js'; import { cfg } from './src/config.js'; const screenshot = (...a) => resolve(cfg.dir.screenshots, 'unrealengine', ...a); @@ -18,21 +19,21 @@ console.log(datetime(), 'started checking unrealengine'); const db = await jsonDb('unrealengine.json', {}); // https://playwright.dev/docs/auth#multi-factor-authentication -const context = await firefox.launchPersistentContext(cfg.dir.browser, { +const context = await chromium.launchPersistentContext(cfg.dir.browser, { headless: cfg.headless, viewport: { width: cfg.width, height: cfg.height }, - userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.83 Safari/537.36', // see replace of Headless in util.newStealthContext. TODO Windows UA enough to avoid 'device not supported'? update if browser is updated? - // userAgent for firefox: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:106.0) Gecko/20100101 Firefox/106.0 - locale: 'en-US', // ignore OS locale to be sure to have english text for locators + locale: 'en-US', // ignore OS locale to be sure to have english text for locators -> done via /en in URL recordVideo: cfg.record ? { dir: 'data/record/', size: { width: cfg.width, height: cfg.height } } : undefined, // will record a .webm video for each page navigated; without size, video would be scaled down to fit 800x800 - recordHar: cfg.record ? { path: `data/record/ue-${filenamify(datetime())}.har` } : undefined, // will record a HAR file with network requests and responses; can be imported in Chrome devtools + recordHar: cfg.record ? { path: `data/record/gog-${filenamify(datetime())}.har` } : undefined, // will record a HAR file with network requests and responses; can be imported in Chrome devtools handleSIGINT: false, // have to handle ourselves and call context.close(), otherwise recordings from above won't be saved + // https://peter.sh/experiments/chromium-command-line-switches/ + args: [ + '--hide-crash-restore-bubble', + ], }); handleSIGINT(context); -await stealth(context); - if (!cfg.debug) context.setDefaultTimeout(cfg.timeout); const page = context.pages().length ? context.pages()[0] : await context.newPage(); // should always exist