From 2012c7e2f2ea5b2b3f7b25ff58cdaf2b27d1d8fe Mon Sep 17 00:00:00 2001 From: Ralf Vogler Date: Thu, 6 Oct 2022 23:33:39 +0200 Subject: [PATCH] eg: set cookie instead of click 'Accept All Cookies' --- epic-games.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/epic-games.js b/epic-games.js index d7ae275..ee2a2d9 100644 --- a/epic-games.js +++ b/epic-games.js @@ -54,10 +54,12 @@ const page = context.pages().length ? context.pages()[0] : await context.newPage // console.debug('userAgent:', await page.evaluate(() => navigator.userAgent)); try { + await context.addCookies([{name: 'OptanonAlertBoxClosed', value: '2022-10-06T21:15:28.081Z', domain: '.epicgames.com', path: '/'}]); + await page.goto(URL_CLAIM, { waitUntil: 'domcontentloaded' }); // 'domcontentloaded' faster than default 'load' https://playwright.dev/docs/api/class-page#page-goto - // Accept cookies to get rid of banner to save space on screen. Will only appear for a fresh context, so we don't await, but let it time out if it does not exist and catch the exception. clickIfExists by checking selector's count > 0 did not work. - page.click('button:has-text("Accept All Cookies")').catch(_ => { }); // _ => console.info('Cookies already accepted') + // Accept cookies to get rid of banner to save space on screen. Clicking this did not always work since the message was animated in too slowly. + // page.click('button:has-text("Accept All Cookies")').catch(_ => { }); // not needed anymore since we set the cookie above while (await page.locator('a[role="button"]:has-text("Sign In")').count() > 0) { // TODO also check alternative for signed-in state console.error("Not signed in anymore. Please login and then navigate to the 'Free Games' page. If using docker, open http://localhost:6080");