use patchright in unrealengine and steam-games (both stale)
This commit is contained in:
parent
4a19e5775e
commit
b3bf92c2d9
2 changed files with 21 additions and 32 deletions
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue