From a97ba1a3da75343d7aa25bf480ec2c7871355e3e Mon Sep 17 00:00:00 2001 From: lucaschungzsj Date: Mon, 16 Mar 2026 13:06:46 +0800 Subject: [PATCH] feat(auth): add manual password input when password not configured When password is empty or whitespace-only, prompt user to input password manually via terminal (120s timeout), similar to existing TOTP manual input flow. Also adds error message checking after password submission. --- src/browser/auth/methods/EmailLogin.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/browser/auth/methods/EmailLogin.ts b/src/browser/auth/methods/EmailLogin.ts index 51985234..868af9b2 100644 --- a/src/browser/auth/methods/EmailLogin.ts +++ b/src/browser/auth/methods/EmailLogin.ts @@ -1,8 +1,10 @@ import type { Page } from 'patchright' import type { MicrosoftRewardsBot } from '../../../index' +import { getErrorMessage, promptInput } from './LoginUtils' export class EmailLogin { private submitButton = 'button[type="submit"]' + private readonly maxManualSeconds = 120 constructor(private bot: MicrosoftRewardsBot) {} @@ -58,6 +60,21 @@ export class EmailLogin { return 'error' } + // 密码为空时,提示手动输入 + password = password?.trim() ? password : '' + if (!password) { + this.bot.logger.info(this.bot.isMobile, 'LOGIN-ENTER-PASSWORD', 'No password provided, awaiting manual input') + password = await promptInput({ + question: `Enter your password (waiting ${this.maxManualSeconds}s): `, + timeoutSeconds: this.maxManualSeconds, + transform: input => input.trim() + }) ?? '' + if (!password) { + this.bot.logger.error(this.bot.isMobile, 'LOGIN-ENTER-PASSWORD', 'Password input timed out') + return 'error' + } + } + await this.bot.utils.wait(1000) await page.fill(passwordInputSelector, '').catch(() => {}) await this.bot.utils.wait(500) @@ -73,6 +90,13 @@ export class EmailLogin { this.bot.logger.info(this.bot.isMobile, 'LOGIN-ENTER-PASSWORD', 'Password submitted') } + await page.waitForLoadState('networkidle', { timeout: 5000 }).catch(() => {}) + const errorMessage = await getErrorMessage(page) + if (errorMessage) { + this.bot.logger.warn(this.bot.isMobile, 'LOGIN-ENTER-PASSWORD', `Password error: ${errorMessage}`) + return 'error' + } + return 'ok' } catch (error) { this.bot.logger.error(