MCPcopy Create free account
hub / github.com/TheNetsky/Microsoft-Rewards-Script / main

Function main

scripts/main/browserSession.js:61–209  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

59}
60
61async function main() {
62 const { dbPath, exists } = getSessionDbPath(projectRoot, config.sessionPath)
63 if (!exists) {
64 log('ERROR', `No sessions.db found (looked for ${dbPath})`)
65 log('ERROR', 'Run the bot at least once so a session is stored for this account.')
66 process.exit(1)
67 }
68
69 const db = openSessionDb(dbPath, { readonly: true })
70
71 let session = null
72 let platform = null
73 for (const p of platformsToTry()) {
74 try {
75 const row = loadSessionRow(db, args.email, p)
76 if (row && (row.storageState || row.fingerprint)) {
77 session = row
78 platform = p
79 break
80 }
81 } catch (error) {
82 log('WARN', `Could not read ${p} session: ${error.message}`)
83 }
84 }
85 closeSessionDb(db)
86
87 if (!session) {
88 log('ERROR', `No stored session for ${args.email} in ${dbPath}`)
89 log('ERROR', 'Run the bot first, or double-check the email.')
90 process.exit(1)
91 }
92
93 const isMobile = platform === 'mobile'
94 const useInjector = engine === 'chromium' || isMobile
95 const { storageState, fingerprint } = session
96 const cookieCount = storageState?.cookies?.length ?? 0
97 const screen = fingerprint?.fingerprint?.screen
98 const userAgent = fingerprint?.fingerprint?.navigator?.userAgent || fingerprint?.fingerprint?.userAgent || null
99
100 const proxy = account ? buildProxyConfig(account) : null
101 if (account?.proxy?.url && (!proxy || !proxy.server)) {
102 log('ERROR', 'Account proxy is configured but invalid (needs proxy url + port)')
103 process.exit(1)
104 }
105
106 log('INFO', `Session: ${args.email} (${platform})`)
107 log('INFO', ` Engine: ${engine}${channel ? ` (channel: ${channel})` : ' (bundled chromium)'}`)
108 log('INFO', ` Cookies: ${cookieCount}`)
109 log('INFO', ` Fingerprint: ${fingerprint ? 'Yes' : 'No'}`)
110 log('INFO', ` Fingerprint injector: ${useInjector ? 'Yes' : 'No (real browser)'}`)
111 log('INFO', ` User-Agent: ${userAgent || 'Default'}`)
112 log('INFO', ` Proxy: ${proxy ? 'Yes' : 'No'}`)
113 log('INFO', ` Updated: ${session.updatedAt ? new Date(session.updatedAt).toISOString() : 'unknown'}`)
114 log('INFO', 'Launching browser...')
115
116 const sandboxArgs = process.platform === 'win32' ? [] : ['--no-sandbox', '--disable-setuid-sandbox']
117 const certArgs = proxy
118 ? ['--ignore-certificate-errors', '--ignore-certificate-errors-spki-list', '--ignore-ssl-errors']

Callers 1

browserSession.jsFile · 0.70

Calls 8

getSessionDbPathFunction · 0.90
logFunction · 0.90
openSessionDbFunction · 0.90
loadSessionRowFunction · 0.90
closeSessionDbFunction · 0.90
buildProxyConfigFunction · 0.90
setupCleanupHandlersFunction · 0.90
platformsToTryFunction · 0.85

Tested by

no test coverage detected