Skip to content

Commit

Permalink
1.3.2
Browse files Browse the repository at this point in the history
- Better generation of mobile user agents
  • Loading branch information
TheNetsky committed Dec 27, 2023
1 parent bca1e7c commit f3fb641
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "microsoft-rewards-script",
"version": "1.3.1",
"version": "1.3.2",
"description": "Automatically do tasks for Microsoft Rewards but in TS!",
"main": "index.js",
"engines": {
Expand Down
22 changes: 18 additions & 4 deletions src/browser/Browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ http://f.vision/

class Browser {
private bot: MicrosoftRewardsBot
private usedUserAgents: string[] = []

constructor(bot: MicrosoftRewardsBot) {
this.bot = bot
Expand All @@ -38,21 +39,34 @@ class Browser {
]
})

const { fingerprint, headers } = new FingerprintGenerator().getFingerprint({
let fingerPrintData = new FingerprintGenerator().getFingerprint({
devices: this.bot.isMobile ? ['mobile'] : ['desktop'],
operatingSystems: this.bot.isMobile ? ['android'] : ['windows'],
browsers: ['edge'],
browserListQuery: 'last 2 Edge versions'
browsers: ['edge']
})

if (this.usedUserAgents) {
while (this.usedUserAgents.includes(fingerPrintData.fingerprint.navigator.userAgent)) {
fingerPrintData = new FingerprintGenerator().getFingerprint({
devices: this.bot.isMobile ? ['mobile'] : ['desktop'],
operatingSystems: this.bot.isMobile ? ['android'] : ['windows'],
browsers: ['edge']
})
}
}

this.usedUserAgents.push(fingerPrintData.fingerprint.navigator.userAgent)

// Modify the newPage function to attach the fingerprint
const originalNewPage = browser.newPage
browser.newPage = async function () {
const page = await originalNewPage.apply(browser)
await new FingerprintInjector().attachFingerprintToPuppeteer(page, { fingerprint, headers })
await new FingerprintInjector().attachFingerprintToPuppeteer(page, fingerPrintData)
return page
}

this.bot.log('BROWSER', `Created browser with User-Agent: "${fingerPrintData.fingerprint.navigator.userAgent}"`)

return browser
}

Expand Down

0 comments on commit f3fb641

Please sign in to comment.