diff --git a/README.md b/README.md index 7c36c0b..3608b52 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,7 @@ Available options/variables and their default values: | VNC_PASSWORD | | VNC password for Docker. No password used by default! | | NOTIFY | | Notification services to use (Pushover, Slack, Telegram...), see below. | | BROWSER_DIR | data/browser | Directory for browser profile, e.g. for multiple accounts. | +| LOGIN_TIMEOUT | 180 | Timeout for login in seconds. | | EMAIL | | Default email for any login. | | PASSWORD | | Default password for any login. | | EG_EMAIL | | Epic Games email for login. Overrides EMAIL. | diff --git a/config.js b/config.js index e7408d4..bdee57e 100644 --- a/config.js +++ b/config.js @@ -12,6 +12,7 @@ export const cfg = { width: Number(process.env.WIDTH) || 1280, // width of the opened browser height: Number(process.env.HEIGHT) || 1280, // height of the opened browser timeout: (Number(process.env.TIMEOUT) || 20) * 1000, // 20s, default for playwright is 30s + login_timeout: (Number(process.env.LOGIN_TIMEOUT) || 180) * 1000, // higher 3min timeout for login novnc_port: process.env.NOVNC_PORT, // running in docker if set notify: process.env.NOTIFY, // apprise notification services get dir() { // avoids ReferenceError: Cannot access 'dataDir' before initialization diff --git a/epic-games.js b/epic-games.js index dff1344..e4f5293 100644 --- a/epic-games.js +++ b/epic-games.js @@ -56,11 +56,11 @@ try { while (await page.locator('a[role="button"]:has-text("Sign In")').count() > 0) { console.error('Not signed in anymore. Please login in the browser or here in the terminal.'); if (cfg.novnc_port) console.info(`Open http://localhost:${cfg.novnc_port} to login inside the docker container.`); - context.setDefaultTimeout(0); // give user time to log in without timeout + if (!cfg.debug) context.setDefaultTimeout(cfg.login_timeout); // give user some extra time to log in + console.info(`Login timeout is ${cfg.login_timeout/1000} seconds!`); await page.goto(URL_LOGIN, { waitUntil: 'domcontentloaded' }); - if (cfg.eg_email && cfg.eg_password) console.info('Using email and password from environment.'); - else console.info('Press ESC to skip if you want to login in the browser.'); + else console.info('Press ESC to skip the prompts if you want to login in the browser (not possible in headless mode).'); const email = cfg.eg_email || await prompt({message: 'Enter email'}); const password = email && (cfg.eg_password || await prompt({type: 'password', message: 'Enter password'})); if (email && password) { @@ -85,7 +85,7 @@ try { notify('epic-games: no longer signed in and not enough options set for automatic login.'); } await page.waitForURL(URL_CLAIM); - context.setDefaultTimeout(cfg.timeout); + if (!cfg.debug) context.setDefaultTimeout(cfg.timeout); } const user = await page.locator('#user span').first().innerHTML(); console.log(`Signed in as ${user}`); diff --git a/gog.js b/gog.js index 568fe80..fade890 100644 --- a/gog.js +++ b/gog.js @@ -40,9 +40,10 @@ try { // it then creates an iframe for the login await page.waitForSelector('#GalaxyAccountsFrameContainer iframe'); // TODO needed? const iframe = page.frameLocator('#GalaxyAccountsFrameContainer iframe'); - context.setDefaultTimeout(0); // give user time to log in without timeout + if (!cfg.debug) context.setDefaultTimeout(cfg.login_timeout); // give user some extra time to log in + console.info(`Login timeout is ${cfg.login_timeout/1000} seconds!`); if (cfg.gog_email && cfg.gog_password) console.info('Using email and password from environment.'); - else console.info('Press ESC to skip if you want to login in the browser (not possible in headless mode).'); + else console.info('Press ESC to skip the prompts if you want to login in the browser (not possible in headless mode).'); const email = cfg.gog_email || await prompt({message: 'Enter email'}); const password = email && (cfg.gog_password || await prompt({type: 'password', message: 'Enter password'})); if (email && password) { @@ -76,7 +77,7 @@ try { process.exit(1); } } - context.setDefaultTimeout(cfg.timeout); + if (!cfg.debug) context.setDefaultTimeout(cfg.timeout); } const user = await page.locator('#menuUsername').first().textContent(); // innerText is uppercase due to styling! console.log(`Signed in as '${user}'`); diff --git a/notify-test.js b/notify-test.js index af883df..d8f4dab 100644 --- a/notify-test.js +++ b/notify-test.js @@ -1,6 +1,4 @@ -import { html_game_list, notify } from "./util.js"; - -const delay = ms => new Promise(resolve => setTimeout(resolve, ms)); +import { delay, html_game_list, notify } from "./util.js"; const URL_CLAIM = 'https://gaming.amazon.com/home'; // dummy URL diff --git a/prime-gaming.js b/prime-gaming.js index 5a3278c..8988557 100644 --- a/prime-gaming.js +++ b/prime-gaming.js @@ -37,9 +37,10 @@ try { while (await page.locator('button:has-text("Sign in")').count() > 0) { console.error('Not signed in anymore.'); await page.click('button:has-text("Sign in")'); - if (!cfg.debug) context.setDefaultTimeout(0); // give user time to log in without timeout + if (!cfg.debug) context.setDefaultTimeout(cfg.login_timeout); // give user some extra time to log in + console.info(`Login timeout is ${cfg.login_timeout/1000} seconds!`); if (cfg.pg_email && cfg.pg_password) console.info('Using email and password from environment.'); - else console.info('Press ESC to skip if you want to login in the browser (not possible in default headless mode).'); + else console.info('Press ESC to skip the prompts if you want to login in the browser (not possible in headless mode).'); const email = cfg.pg_email || await prompt({message: 'Enter email'}); const password = email && (cfg.pg_password || await prompt({type: 'password', message: 'Enter password'})); if (email && password) { @@ -67,7 +68,7 @@ try { console.log('Waiting for you to login in the browser.'); notify('prime-gaming: no longer signed in and not enough options set for automatic login.'); if (cfg.headless) { - console.log('Please run `SHOW=1 node prime-gaming` to login in the opened browser.'); + console.log('Run `SHOW=1 node prime-gaming` to login in the opened browser.'); await context.close(); // finishes potential recording process.exit(1); } diff --git a/util.js b/util.js index d64b94b..c7c3bc9 100644 --- a/util.js +++ b/util.js @@ -17,6 +17,7 @@ export const jsonDb = async file => { }; +export const delay = ms => new Promise(resolve => setTimeout(resolve, ms)); // date and time as UTC (no timezone offset) in nicely readable and sortable format, e.g., 2022-10-06 12:05:27.313 export const datetime = (d = new Date()) => d.toISOString().replace('T', ' ').replace('Z', ''); // same as datetime() but for local timezone, e.g., UTC + 2h for the above in DE