@@ -11,15 +11,7 @@ import {
1111import { getCookiesRaw , setPuppeteerCookies , userHasValidCookie } from '../common/cookie.js' ;
1212import { config } from '../common/config/index.js' ;
1313import { getAccountAuth } from '../common/device-auths.js' ;
14- import {
15- ACCOUNT_EULA_HISTORY_ENDPOINT ,
16- STORE_CART_EN ,
17- STORE_HOMEPAGE ,
18- } from '../common/constants.js' ;
19- import { generateLoginRedirect } from '../purchase.js' ;
20- import { sendNotification } from '../notify.js' ;
21- import { NotificationReason } from '../interfaces/notification-reason.js' ;
22- import { EulaResponse } from '../interfaces/accounts.js' ;
14+ import { STORE_CART_EN } from '../common/constants.js' ;
2315
2416export interface PuppetBaseProps {
2517 browser : Browser ;
@@ -100,34 +92,11 @@ export default class PuppetBase {
10092 return resp ;
10193 }
10294
103- private async checkEula ( ) : Promise < void > {
104- const REQUIRED_EULAS = [ 'epicgames_privacy_policy_no_table' , 'egstore' ] ;
105- this . L . trace (
106- { url : ACCOUNT_EULA_HISTORY_ENDPOINT , requiredEulas : REQUIRED_EULAS } ,
107- 'Checking acount EULA history' ,
108- ) ;
109- const resp = await this . request < EulaResponse > ( 'GET' , ACCOUNT_EULA_HISTORY_ENDPOINT ) ;
110- this . L . debug ( { resp } , 'Eula history response' ) ;
111- const acceptedEulaKeys = resp . data
112- . filter ( ( eulaEntry ) => eulaEntry . accepted )
113- . map ( ( eulaEntry ) => eulaEntry . key ) ;
114- const hasRequiredEulas = REQUIRED_EULAS . every ( ( requiredKey ) =>
115- acceptedEulaKeys . includes ( requiredKey ) ,
116- ) ;
117-
118- if ( ! hasRequiredEulas ) {
119- this . L . error ( 'User needs to log in an accept an updated EULA' ) ;
120- const actionUrl = generateLoginRedirect ( STORE_HOMEPAGE ) ;
121- sendNotification ( this . email , NotificationReason . PRIVACY_POLICY_ACCEPTANCE , actionUrl ) ;
122- throw new Error ( `${ this . email } needs to accept an updated EULA` ) ;
123- }
124- }
125-
12695 protected async setupPage ( ) : Promise < Page > {
12796 // Get cookies or latest access_token cookies
12897 let puppeteerCookies : Cookie [ ] = [ ] ;
12998 if ( userHasValidCookie ( this . email , 'EPIC_BEARER_TOKEN' ) ) {
130- this . L . debug ( 'Setting auth from cookies' ) ;
99+ this . L . debug ( 'Setting auth from bearer token cookies' ) ;
131100 const userCookies = await getCookiesRaw ( this . email ) ;
132101 puppeteerCookies = toughCookieFileStoreToPuppeteerCookie ( userCookies ) ;
133102 } else {
@@ -162,9 +131,8 @@ export default class PuppetBase {
162131 this . page = await safeNewPage ( this . browser , this . L ) ;
163132 try {
164133 this . L . trace ( getDevtoolsUrl ( this . page ) ) ;
165- await this . page . goto ( STORE_CART_EN , { waitUntil : 'networkidle0' } ) ;
166- await this . browser . setCookie ( ...puppeteerCookies ) ; // must happen **after** navigating
167- await this . checkEula ( ) ;
134+ await this . browser . setCookie ( ...puppeteerCookies ) ;
135+ await this . page . goto ( STORE_CART_EN , { waitUntil : 'networkidle0' } ) ; // Get EG1 cookie
168136 return this . page ;
169137 } catch ( err ) {
170138 await this . handlePageError ( err ) ;
@@ -179,15 +147,15 @@ export default class PuppetBase {
179147 const currentCookies = await this . browser . cookies ( ) ;
180148 setPuppeteerCookies ( this . email , currentCookies ) ;
181149 this . L . trace ( 'Saved cookies, closing browser' ) ;
182- await this . page . close ( ) ;
150+ // await this.page.close(); // Getting `Protocol error (Target.createTarget): Target closed` with this for some reason
183151 this . page = undefined ;
184152 } catch ( err ) {
185153 await this . handlePageError ( err ) ;
186154 }
187155 }
188156
189157 protected async handlePageError ( err : unknown ) {
190- if ( this . page ) {
158+ if ( this . page && ! this . page . isClosed ( ) ) {
191159 const errorFile = `error-${ new Date ( ) . toISOString ( ) } .png` ;
192160 await ensureDir ( config . errorsDir ) ;
193161 await this . page . screenshot ( {
@@ -198,8 +166,8 @@ export default class PuppetBase {
198166 'Encountered an error during browser automation. Saved a screenshot for debugging purposes.' ,
199167 ) ;
200168 await this . page . close ( ) ;
201- this . page = undefined ;
202169 }
170+ this . page = undefined ;
203171 throw err ;
204172 }
205173}
0 commit comments