use patchright in unrealengine and steam-games (both stale)

This commit is contained in:
Ralf Vogler 2025-05-27 00:05:13 +02:00
parent 4a19e5775e
commit b3bf92c2d9
2 changed files with 21 additions and 32 deletions

View file

@ -1,36 +1,24 @@
import { firefox } from 'playwright-firefox'; // stealth plugin needs no outdated playwright-extra // import { firefox } from 'playwright-firefox';
import { jsonDb, prompt } from './src/util.js'; import { chromium } from 'patchright';
import { datetime, filenamify, jsonDb, prompt } from './src/util.js';
import { cfg } from './src/config.js'; import { cfg } from './src/config.js';
const db = await jsonDb('steam-games.json', {}); 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)' }); 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... const context = await chromium.launchPersistentContext(cfg.dir.browser, {
// 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, {
headless: cfg.headless, headless: cfg.headless,
// viewport: { width: cfg.width, height: cfg.height }, // 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 locale: 'en-US', // ignore OS locale to be sure to have english text for locators -> done via /en in URL
userAgent: fingerprint.navigator.userAgent, 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
viewport: { 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
width: fingerprint.screen.width, handleSIGINT: false, // have to handle ourselves and call context.close(), otherwise recordings from above won't be saved
height: fingerprint.screen.height, // https://peter.sh/experiments/chromium-command-line-switches/
}, args: [
extraHTTPHeaders: { '--hide-crash-restore-bubble',
'accept-language': headers['accept-language'], ],
},
}); });
// await stealth(context);
await new FingerprintInjector().attachFingerprintToPlaywright(context, { fingerprint, headers });
context.setDefaultTimeout(cfg.debug ? 0 : cfg.timeout); context.setDefaultTimeout(cfg.debug ? 0 : cfg.timeout);

View file

@ -1,11 +1,12 @@
// TODO This is mostly a copy of epic-games.js // TODO This is mostly a copy of epic-games.js
// New assets to claim every first Tuesday of a month. // 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 { authenticator } from 'otplib';
import path from 'path'; import path from 'path';
import { writeFileSync } from 'fs'; 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'; import { cfg } from './src/config.js';
const screenshot = (...a) => resolve(cfg.dir.screenshots, 'unrealengine', ...a); 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', {}); const db = await jsonDb('unrealengine.json', {});
// https://playwright.dev/docs/auth#multi-factor-authentication // 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, headless: cfg.headless,
viewport: { width: cfg.width, height: cfg.height }, 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? locale: 'en-US', // ignore OS locale to be sure to have english text for locators -> done via /en in URL
// 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
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 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 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); handleSIGINT(context);
await stealth(context);
if (!cfg.debug) context.setDefaultTimeout(cfg.timeout); if (!cfg.debug) context.setDefaultTimeout(cfg.timeout);
const page = context.pages().length ? context.pages()[0] : await context.newPage(); // should always exist const page = context.pages().length ? context.pages()[0] : await context.newPage(); // should always exist