add LOGIN_TIMEOUT (180s) for PW, but prompts still wait forever
This commit is contained in:
parent
704c4b01e1
commit
8c2ac3b6d0
7 changed files with 16 additions and 13 deletions
|
|
@ -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. |
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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}`);
|
||||
|
|
|
|||
7
gog.js
7
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}'`);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
1
util.js
1
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue