Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ accounts.main.json
.DS_Store
.playwright-chromium-installed
bun.lock
logs/
5 changes: 5 additions & 0 deletions .stfolder/syncthing-folder-559ab3.txt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvm it was deleted, didn't see full diff.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This directory is a Syncthing folder marker.
# Do not delete.

folderID: suyn5-qwmnz
created: 2026-01-16T13:55:02+07:00
38 changes: 28 additions & 10 deletions src/browser/auth/Login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type LoginState =
| 'LOGIN_PASSWORDLESS'
| 'GET_A_CODE'
| 'GET_A_CODE_2'
| 'OTP_CODE_ENTRY'
| 'UNKNOWN'
| 'CHROMEWEBDATA_ERROR'

Expand Down Expand Up @@ -58,7 +59,8 @@ export class Login {
viewFooter: '[data-testid="viewFooter"] >> [role="button"]',
bingProfile: '#id_n',
requestToken: 'input[name="__RequestVerificationToken"]',
requestTokenMeta: 'meta[name="__RequestVerificationToken"]'
requestTokenMeta: 'meta[name="__RequestVerificationToken"]',
otpInput: 'div[data-testid="codeEntry"]'
} as const

constructor(private bot: MicrosoftRewardsBot) {
Expand All @@ -73,7 +75,7 @@ export class Login {
try {
this.bot.logger.info(this.bot.isMobile, 'LOGIN', 'Starting login process')

await page.goto('https://www.bing.com/rewards/dashboard', { waitUntil: 'domcontentloaded' }).catch(() => {})
await page.goto('https://www.bing.com/rewards/dashboard', { waitUntil: 'domcontentloaded' }).catch(() => { })
await this.bot.utils.wait(2000)
await this.bot.browser.utils.reloadBadPage(page)
await this.bot.browser.utils.disableFido(page)
Expand Down Expand Up @@ -149,7 +151,7 @@ export class Login {
}

private async detectCurrentState(page: Page, account?: Account): Promise<LoginState> {
await page.waitForLoadState('networkidle', { timeout: 5000 }).catch(() => {})
await page.waitForLoadState('networkidle', { timeout: 5000 }).catch(() => { })

const url = new URL(page.url())
this.bot.logger.debug(this.bot.isMobile, 'DETECT-STATE', `Current URL: ${url.hostname}${url.pathname}`)
Expand Down Expand Up @@ -183,7 +185,8 @@ export class Login {
[this.selectors.emailIconOld, 'SIGN_IN_ANOTHER_WAY_EMAIL'],
[this.selectors.passwordlessCheck, 'LOGIN_PASSWORDLESS'],
[this.selectors.totpInput, '2FA_TOTP'],
[this.selectors.totpInputOld, '2FA_TOTP']
[this.selectors.totpInputOld, '2FA_TOTP'],
[this.selectors.otpInput, 'OTP_CODE_ENTRY']
]

const results = await Promise.all(
Expand Down Expand Up @@ -381,7 +384,7 @@ export class Login {
waitUntil: 'domcontentloaded',
timeout: 10000
})
.catch(() => {})
.catch(() => { })
await this.bot.utils.wait(3000)
this.bot.logger.info(this.bot.isMobile, 'LOGIN', 'Recovery navigation successful')
return true
Expand All @@ -392,7 +395,7 @@ export class Login {
waitUntil: 'domcontentloaded',
timeout: 10000
})
.catch(() => {})
.catch(() => { })
await this.bot.utils.wait(3000)
this.bot.logger.info(this.bot.isMobile, 'LOGIN', 'Fallback navigation successful')
return true
Expand Down Expand Up @@ -447,6 +450,21 @@ export class Login {
return true
}

case 'OTP_CODE_ENTRY': {
this.bot.logger.info(this.bot.isMobile, 'LOGIN', 'OTP code entry page detected, clicking back to find password option')

// Click the "Use your password" footer/link
// The HTML shows it as data-testid="viewFooter" which contains "Use your password"

await this.bot.browser.utils.ghostClick(page, this.selectors.viewFooter)
await page.waitForLoadState('networkidle', { timeout: 5000 }).catch(() => {
this.bot.logger.debug(this.bot.isMobile, 'LOGIN', 'Network idle timeout after footer click in OTP entry')
})

this.bot.logger.info(this.bot.isMobile, 'LOGIN', 'Navigated back from OTP entry page')
return true
}

case 'UNKNOWN': {
const url = new URL(page.url())
this.bot.logger.warn(
Expand All @@ -466,7 +484,7 @@ export class Login {
private async finalizeLogin(page: Page, email: string) {
this.bot.logger.info(this.bot.isMobile, 'LOGIN', 'Finalizing login')

await page.goto(this.bot.config.baseURL, { waitUntil: 'networkidle', timeout: 10000 }).catch(() => {})
await page.goto(this.bot.config.baseURL, { waitUntil: 'networkidle', timeout: 10000 }).catch(() => { })

const loginRewardsSuccess = new URL(page.url()).hostname === 'rewards.bing.com'
if (loginRewardsSuccess) {
Expand Down Expand Up @@ -497,7 +515,7 @@ export class Login {
this.bot.logger.info(this.bot.isMobile, 'LOGIN-BING', 'Verifying Bing session')

try {
await page.goto(url, { waitUntil: 'networkidle', timeout: 10000 }).catch(() => {})
await page.goto(url, { waitUntil: 'networkidle', timeout: 10000 }).catch(() => { })

for (let i = 0; i < loopMax; i++) {
if (page.isClosed()) break
Expand All @@ -519,7 +537,7 @@ export class Login {
)

if (atBingHome) {
await this.bot.browser.utils.tryDismissAllMessages(page).catch(() => {})
await this.bot.browser.utils.tryDismissAllMessages(page).catch(() => { })

const signedIn = await page
.waitForSelector(this.selectors.bingProfile, { timeout: 3000 })
Expand Down Expand Up @@ -555,7 +573,7 @@ export class Login {
try {
await page
.goto(`${this.bot.config.baseURL}?_=${Date.now()}`, { waitUntil: 'networkidle', timeout: 10000 })
.catch(() => {})
.catch(() => { })

for (let i = 0; i < loopMax; i++) {
if (page.isClosed()) break
Expand Down
4 changes: 2 additions & 2 deletions src/logging/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function formatMessage(message: string | Error): string {
}

export class Logger {
constructor(private bot: MicrosoftRewardsBot) {}
constructor(private bot: MicrosoftRewardsBot) { }

info(isMobile: Platform, title: string, message: string, color?: ColorKey) {
return this.baseLog('info', isMobile, title, message, color)
Expand Down Expand Up @@ -180,7 +180,7 @@ export class Logger {
isMatch = true
break
}
} catch {}
} catch { }
}
}

Expand Down