From 066a99c77c9cc78baa71c2abe467385830269280 Mon Sep 17 00:00:00 2001 From: Ralf Vogler Date: Fri, 5 May 2023 09:54:21 +0200 Subject: [PATCH] eg: RECORD=1 to recordVideo & recordHar --- config.js | 1 + epic-games.js | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/config.js b/config.js index 33016ca..32974e1 100644 --- a/config.js +++ b/config.js @@ -6,6 +6,7 @@ dotenv.config({ path: 'data/config.env' }); // loads env vars from file - will n // Options - also see table in README.md export const cfg = { debug: process.env.PWDEBUG == '1', // runs non-headless and opens https://playwright.dev/docs/inspector + record: process.env.RECORD == '1', // `recordHar` (network) + `recordVideo` dryrun: process.env.DRYRUN == '1', // don't claim anything show: process.env.SHOW == '1', // run non-headless get headless() { return !this.debug && !this.show }, diff --git a/epic-games.js b/epic-games.js index c38bdfc..a107a1f 100644 --- a/epic-games.js +++ b/epic-games.js @@ -27,7 +27,8 @@ const context = await firefox.launchPersistentContext(cfg.dir.browser, { 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 - // recordVideo: { dir: 'data/videos/' }, // will record a .webm video for each page navigated + recordVideo: cfg.record && { dir: 'data/record/', size: { width: cfg.width, height: cfg.height } }, // 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/eg-${datetime()}.har` }, // will record a HAR file with network requests and responses; can be imported in Chrome devtools args: [ // https://peter.sh/experiments/chromium-command-line-switches // don't want to see bubble 'Restore pages? Chrome didn't shut down correctly.' // '--restore-last-session', // does not apply for crash/killed @@ -45,6 +46,12 @@ if (!cfg.debug) context.setDefaultTimeout(cfg.timeout); const page = context.pages().length ? context.pages()[0] : await context.newPage(); // should always exist // console.debug('userAgent:', await page.evaluate(() => navigator.userAgent)); +if (cfg.record && cfg.debug) { + // const filter = _ => true; + const filter = r => r.url().includes('store.epicgames.com'); + page.on('request', request => filter(request) && console.log('>>', request.method(), request.url())); + page.on('response', response => filter(response) && console.log('<<', response.status(), response.url())); +} const notify_games = []; let user;