From 09c3e57a8adc74a66216f322578239cb447f8bcf Mon Sep 17 00:00:00 2001 From: Ralf Vogler Date: Sat, 7 Jan 2023 13:47:08 +0100 Subject: [PATCH] use SHOW for pg and eg, headless by default for both, but show inside Docker --- Dockerfile | 3 +++ epic-games.js | 4 +++- prime-gaming.js | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index ceeabf5..4aa43c8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -56,6 +56,9 @@ ENV SCREEN_WIDTH 1280 ENV SCREEN_HEIGHT 1280 ENV SCREEN_DEPTH 24 +# Show browser instead of running headless +ENV SHOW 1 + # Script to setup display server & VNC is always executed. ENTRYPOINT ["entrypoint"] # Default command to run. This is replaced by appending own command, e.g. `docker run ... node prime-gaming` to only run this script. diff --git a/epic-games.js b/epic-games.js index b1b97c9..e2562fb 100644 --- a/epic-games.js +++ b/epic-games.js @@ -9,6 +9,8 @@ import prompts from 'prompts'; // alternatives: enquirer, inquirer const prompt = async o => (await prompts({name: 'name', type: 'text', message: 'Enter value', validate: s => s.length, ...o})).name; const debug = process.env.PWDEBUG == '1'; // runs non-headless and opens https://playwright.dev/docs/inspector +const show = process.env.SHOW == '1'; +const headless = !debug && !show; const URL_CLAIM = 'https://store.epicgames.com/en-US/free-games'; const URL_LOGIN = 'https://www.epicgames.com/id/login?lang=en-US&noHostRedirect=true&redirectUrl=' + URL_CLAIM; @@ -38,7 +40,7 @@ const ext = path.resolve('nopecha'); // used in Chromium, currently not needed i const context = await firefox.launchPersistentContext(dirs.browser, { // chrome will not work in linux arm64, only chromium // channel: 'chrome', // https://playwright.dev/docs/browsers#google-chrome--microsoft-edge - headless: false, + headless, viewport: { width: SCREEN_WIDTH, height: SCREEN_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 diff --git a/prime-gaming.js b/prime-gaming.js index f56cafd..e77d7d1 100644 --- a/prime-gaming.js +++ b/prime-gaming.js @@ -8,7 +8,7 @@ import prompts from 'prompts'; // alternatives: enquirer, inquirer const prompt = async o => (await prompts({name: 'name', type: 'text', message: 'Enter value', validate: s => s.length, ...o})).name; const debug = process.env.PWDEBUG == '1'; // runs non-headless and opens https://playwright.dev/docs/inspector -const show = process.argv.includes('show', 2); +const show = process.env.SHOW == '1'; const headless = !debug && !show; // const URL_LOGIN = 'https://www.amazon.de/ap/signin'; // wrong. needs some session args to be valid?