Skip to content

Commit 64048e3

Browse files
committed
1.4.5
- Fix login not working - Sessions are now saved after logging in - Check if promotions, and searches are available before counting total point amount
1 parent cf7f7ac commit 64048e3

File tree

5 files changed

+26
-20
lines changed

5 files changed

+26
-20
lines changed

Diff for: package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "microsoft-rewards-script",
3-
"version": "1.4.4",
3+
"version": "1.4.5",
44
"description": "Automatically do tasks for Microsoft Rewards but in TS!",
55
"main": "index.js",
66
"engines": {
@@ -34,9 +34,9 @@
3434
"dependencies": {
3535
"axios": "^1.6.7",
3636
"cheerio": "^1.0.0-rc.12",
37-
"fingerprint-generator": "^2.1.48",
38-
"fingerprint-injector": "^2.1.48",
39-
"playwright": "^1.41.2",
37+
"fingerprint-generator": "^2.1.49",
38+
"fingerprint-injector": "^2.1.49",
39+
"playwright": "^1.42.0",
4040
"ts-node": "^10.9.2"
4141
}
4242
}

Diff for: src/browser/BrowserFunc.ts

+11-7
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ export default class BrowserFunc {
142142
let totalEarnablePoints = 0
143143

144144
// Desktop Search Points
145-
data.userStatus.counters.pcSearch.forEach(x => totalEarnablePoints += (x.pointProgressMax - x.pointProgress))
145+
if (data.userStatus.counters.pcSearch?.length) {
146+
data.userStatus.counters.pcSearch.forEach(x => totalEarnablePoints += (x.pointProgressMax - x.pointProgress))
147+
}
146148

147149
// Mobile Search Points
148150
if (data.userStatus.counters.mobileSearch?.length) {
@@ -153,12 +155,14 @@ export default class BrowserFunc {
153155
data.dailySetPromotions[this.bot.utils.getFormattedDate()]?.forEach(x => totalEarnablePoints += (x.pointProgressMax - x.pointProgress))
154156

155157
// More Promotions
156-
data.morePromotions.forEach(x => {
157-
// Only count points from supported activities
158-
if (['quiz', 'urlreward'].includes(x.activityType)) {
159-
totalEarnablePoints += (x.pointProgressMax - x.pointProgress)
160-
}
161-
})
158+
if (data.morePromotions?.length) {
159+
data.morePromotions.forEach(x => {
160+
// Only count points from supported activities
161+
if (['quiz', 'urlreward'].includes(x.activityType)) {
162+
totalEarnablePoints += (x.pointProgressMax - x.pointProgress)
163+
}
164+
})
165+
}
162166

163167
return totalEarnablePoints
164168
} catch (error) {

Diff for: src/functions/Login.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Page } from 'playwright'
22
import readline from 'readline'
33

44
import { MicrosoftRewardsBot } from '../index'
5+
import { saveSessionData } from '../util/Load'
56

67
const rl = readline.createInterface({
78
input: process.stdin,
@@ -26,14 +27,12 @@ export class Login {
2627

2728
if (!isLoggedIn) {
2829
// Check if account is locked
29-
const isLocked = await page.waitForSelector('.serviceAbusePageContainer', { state: 'visible', timeout: 10_000 }).then(() => true).catch(() => false)
30+
const isLocked = await page.waitForSelector('.serviceAbusePageContainer', { state: 'visible', timeout: 1000 }).then(() => true).catch(() => false)
3031
if (isLocked) {
3132
this.bot.log('LOGIN', 'This account has been locked!', 'error')
3233
throw new Error('Account has been locked!')
3334
}
3435

35-
await page.waitForSelector('#loginHeader', { state: 'visible', timeout: 10_000 })
36-
3736
await this.execLogin(page, email, password)
3837
this.bot.log('LOGIN', 'Logged into Microsoft successfully')
3938
} else {
@@ -43,6 +42,9 @@ export class Login {
4342
// Check if logged in to bing
4443
await this.checkBingLogin(page)
4544

45+
// Save session
46+
await saveSessionData(this.bot.config.sessionPath, page.context(), email, this.bot.isMobile)
47+
4648
// We're done logging in
4749
this.bot.log('LOGIN', 'Logged in successfully')
4850

Diff for: src/index.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,7 @@ export class MicrosoftRewardsBot {
178178
}
179179

180180
// Save cookies
181-
const cookies = await browser.cookies()
182-
await saveSessionData(this.config.sessionPath, account.email, this.isMobile, cookies)
181+
await saveSessionData(this.config.sessionPath, browser, account.email, this.isMobile)
183182

184183
// Close desktop browser
185184
return await this.closeBrowser(browser, account.email)
@@ -247,8 +246,7 @@ export class MicrosoftRewardsBot {
247246

248247
private async closeBrowser(browser: BrowserContext, email: string) {
249248
// Save cookies
250-
const cookies = await browser.cookies()
251-
await saveSessionData(this.config.sessionPath, email, this.isMobile, cookies)
249+
await saveSessionData(this.config.sessionPath, browser, email, this.isMobile)
252250

253251
// Close browser
254252
await browser.close()

Diff for: src/util/Load.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Cookie } from 'playwright'
1+
import { BrowserContext, Cookie } from 'playwright'
22
import { BrowserFingerprintWithHeaders } from 'fingerprint-generator'
33
import fs from 'fs'
44
import path from 'path'
@@ -67,8 +67,10 @@ export async function loadSessionData(sessionPath: string, email: string, isMobi
6767
}
6868
}
6969

70-
export async function saveSessionData(sessionPath: string, email: string, isMobile: boolean, cookies: Cookie[]): Promise<string> {
70+
export async function saveSessionData(sessionPath: string, browser: BrowserContext, email: string, isMobile: boolean): Promise<string> {
7171
try {
72+
const cookies = await browser.cookies()
73+
7274
// Fetch path
7375
const sessionDir = path.join(__dirname, '../browser/', sessionPath, email)
7476

0 commit comments

Comments
 (0)