()
| 35 | } |
| 36 | |
| 37 | protected async setupPage(): Promise<Page> { |
| 38 | // Get cookies or latest access_token cookies |
| 39 | let puppeteerCookies: Protocol.Network.CookieParam[] = []; |
| 40 | if (userHasValidCookie(this.email, 'EPIC_BEARER_TOKEN')) { |
| 41 | this.L.debug('Setting auth from cookies'); |
| 42 | const userCookies = await getCookiesRaw(this.email); |
| 43 | puppeteerCookies = toughCookieFileStoreToPuppeteerCookie(userCookies); |
| 44 | } else { |
| 45 | const deviceAuth = getAccountAuth(this.email); |
| 46 | if (!deviceAuth) throw new Error(`Unable to get auth for user ${this.email}`); |
| 47 | this.L.debug({ deviceAuth }, 'Setting auth from device auth'); |
| 48 | const bearerCookies: Protocol.Network.CookieParam[] = [ |
| 49 | '.epicgames.com', |
| 50 | '.twinmotion.com', |
| 51 | '.fortnite.com', |
| 52 | '.unrealengine.com', |
| 53 | ].map((domain) => ({ |
| 54 | name: 'EPIC_BEARER_TOKEN', |
| 55 | value: deviceAuth.access_token, |
| 56 | expires: new Date(deviceAuth.expires_at).getTime() / 1000, |
| 57 | domain, |
| 58 | path: '/', |
| 59 | secure: true, |
| 60 | httpOnly: true, |
| 61 | sameSite: 'Lax', |
| 62 | })); |
| 63 | puppeteerCookies.push(...bearerCookies); |
| 64 | } |
| 65 | this.L.debug('Logging in with puppeteer'); |
| 66 | const browser = await safeLaunchBrowser(this.L); |
| 67 | const page = await safeNewPage(browser, this.L); |
| 68 | try { |
| 69 | this.L.trace(getDevtoolsUrl(page)); |
| 70 | const cdpClient = await page.target().createCDPSession(); |
| 71 | await cdpClient.send('Network.setCookies', { |
| 72 | cookies: puppeteerCookies, |
| 73 | }); |
| 74 | await cdpClient.detach(); |
| 75 | await page.setCookie(...puppeteerCookies); |
| 76 | await page.goto(STORE_HOMEPAGE, { waitUntil: 'networkidle2' }); |
| 77 | return page; |
| 78 | } catch (err) { |
| 79 | await this.handlePageError(err, page); |
| 80 | throw err; |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | protected async teardownPage(page: Page): Promise<void> { |
| 85 | try { |
no test coverage detected